Francis
Francis

Reputation: 1151

How do you run cl.exe from cmd using the same settings as in MSVS?

I have a c++ project in MSVS 2010 Express. I have been planning to write several unit tests to validate this project. Right now they go along the following lines:

#include "header.h" //Header is the header for the source I want to test

void testSomeFunction()
{
    //Call function (from external src, prototype in header.h)
    //Save output to file
}

int main()
{
    testSomeFunction();
    return 0;
}

I am creating these source files outside my project because I want to be able to run each of them as individual executable, but I am having trouble getting the Microsoft linker to link them.

This is my problem so far (CMD output):

cl ut_Converter.cpp Converter.obj

ut_Converter.cpp
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xlocale(323) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc

Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:ut_Converter.exe
ut_Converter.obj
Converter.obj
Converter.obj : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in ut_Converter.obj
Converter.obj : fatal error LNK1313: pure module detected; cannot link with ijw/native modules

I never really use Microsoft products, I'm familiar with using the GNU tools GCC and make but I have to use the Microsoft tools for this and I have no idea how they work.

Maybe I'm going about building these tests the stupid way but it's the best way I can think of right now.

This is what I want to do:

  1. Compile the source files in my project into object files
  2. Compile my test files into object files
  3. Link the test object file with the appropriate project object files to produce the test executable

How do I go about doing that? (I'm guessing there are some settings I need to set to make everything compatible but I have no idea what they are or how I would go about setting them)

Extra: I know it mentions the debug level but I'd be willing to bet that there will be other incompatible settings. Is there a way to find out what the settings are in the program so I can pass them to cl.exe when I run it?

Edit: When I say command prompt I do mean the one that comes with Visual Studio with all the environment variables setup.

Upvotes: 0

Views: 555

Answers (1)

rcgldr
rcgldr

Reputation: 28826

Have you tried going to Programs / Microsoft Visual ... / ... Tools / ... Command Prompt, and running from that dos console window which has the environment variables setup?

Upvotes: 2

Related Questions