View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Visual Studio 2012 Command Line Building Woes

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1Lith  Members

Posted 01 May 2014 - 11:38 AM

This is the first time I have tried to download source from the web and compile it myself. This is also the first time I'm building a relatively large project on the command line..

I'm using Visual Studio 2012's cl.exe tool to build. I've pushed through a number of errors so far but this one's been bugging me for a few days. The project compiles fine but it won't link. It complains of the entry point not being defined:

LINK1561: entry point must be defined.

I've checked that the main.cpp file is being built and checked that there is a valid main function inside. I'm pretty sure it has something to do with the project depending on SDL. If it matters, I'm not sure I'm using the same version of SDL that the code was written for. A few years back I was writing small games with SDL and I have vague memories of it being very picky with regards to entry points. You had to link to SDLmain.lib and define the main function with all command line argument arguments.

Here's my super sexy home grown makefile:

CC=comp.bat
SRC_SOURCE=*.cpp
SRC_INC_1=C:\DevLib\SDL_1.2\SDL-1.2.15\include
SRC_INC_2=C:\DevLib\SDL_1.2\SDL_image-1.2.12\include
LIB_PATH_1=C:\DevLib\SDL_1.2\SDL-1.2.15\lib\x86
LIB_PATH_2=C:\DevLib\SDL_1.2\SDL_image-1.2.12\lib\x86
LIB_PATH_3=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\lib;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib;
LIB=SDL.lib SDLmain.lib SDL_image.lib

all: $(SRC_SOURCE)$(SRC_HEADER)
$(CC)$(SRC_SOURCE) /I$(SRC_INC_1) /I$(SRC_INC_2) /EHsc /link SDLmain.lib SDL.lib SDL_image.lib /LIBPATH:"$(LIB_PATH_1)" /LIBPATH:"$(LIB_PATH_2)"

clear:
del *.obj
del *.exe


As i'm sure you'll notice, not all of my LIB_PATH macros are being used. Some of them are scars from previous struggles..

Here is comp.bat: (I found this online somewhere)

@echo on
call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
:: Invoke compiler with any options passed to this batch file
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.exe" %*


Please tell me if there's any vital info I have omitted. All help is appreciated, thanks.

### #2Karsten_  Members

Posted 01 May 2014 - 12:08 PM

After you have called vcvarsall.bat, you should only have to call cl.exe rather than the full path since your path env variable has now been extended to include the VC/bin directory.

The error you are getting is because it is not finding either the main or winmain functions.

As I recall, SDL is a little bit screwy on Windows so I think it needs /SUBSYSTEM:CONSOLE to be defined as a compiler flag.

Perhaps try putting that either before or after the /link argument.

http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

### #3Lactose  GDNet+

Posted 01 May 2014 - 12:13 PM

Since you mentioned SDL:
I seem to remember SDL requiring the use of a specific main function, i.e. more strict that e.g. Windows does natively.

While int main() will work for normal stuff, I think SDL requires the function to be int main(int argc, char *argv[]).

This might not be your problem (you didn't post your actual function), but it's worth double checking.

Hello to all my stalkers.

### #4Endurion  Members

Posted 01 May 2014 - 01:15 PM

AFAIR for SDL 1.2 to link you also had to link a second library containing the hidden WinMain function.

e.g. SDL.lib and SDLmain.lib

Edited by Endurion, 01 May 2014 - 01:15 PM.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

### #5Lith  Members

Posted 05 May 2014 - 01:13 PM

After you have called vcvarsall.bat, you should only have to call cl.exe rather than the full path since your path env variable has now been extended to include the VC/bin directory.

The error you are getting is because it is not finding either the main or winmain functions.

As I recall, SDL is a little bit screwy on Windows so I think it needs /SUBSYSTEM:CONSOLE to be defined as a compiler flag.

Perhaps try putting that either before or after the /link argument.

That seemed to do the trick, thanks!

I'm still not out of the woods yet though.. I was having trouble before where I think I was linking to too many standard libs because, while in msvcrt.lib, it complained of functions being already defined in LIBCMT.lib. So I added this to the linker options

NODEFAULTLIB:msvcrt.lib

And that brings me to my present situation.

Now I'm getting a few warnings followed by some unresolved externals:

SDLmain.lib WARNING LINK4217: Locally defined symbol _exit imported in function _main
SDLmain.lib WARNING LINK4217: Locally defined symbol _strrchr imported in function _main
SDLmain.lib WARNING LINK4217: Locally defined symbol ___iob_func imported in function _main
SDLmain.lib WARNING LINK4217: Locally defined symbol _fgetc imported in function _main
SDLmain.lib WARNING LINK4217: Locally defined symbol _fopen imported in function _main
*a few more of these*
SDLmain.lib ERROR LINK2019: unresolved external sumbol __imp__fprintf referenced in function _ShowError
.. And so on

Here's my full makefile:

CC=comp.bat
SRC_SOURCE=*.cpp
SRC_INC_1=C:\DevLib\SDL_1.2\SDL-1.2.15\include
SRC_INC_2=C:\DevLib\SDL_1.2\SDL_image-1.2.12\include
LIB_PATH_1=C:\DevLib\SDL_1.2\SDL-1.2.15\lib\x86
LIB_PATH_2=C:\DevLib\SDL_1.2\SDL_image-1.2.12\lib\x86
LIB=SDL.lib SDLmain.lib SDL_image.lib

all: $(SRC_SOURCE)$(SRC_HEADER)
$(CC)$(SRC_SOURCE) /I$(SRC_INC_1) /I$(SRC_INC_2) /EHsc /link SDL.lib SDLmain.lib SDL_image.lib /SUBSYSTEM:CONSOLE /NODEFAULTLIB:msvcrt.lib /LIBPATH:"\$(LIB_PATH_1)"

clear:
del *.obj
del *.exe


Edited by Lith, 05 May 2014 - 01:14 PM.

### #6Karsten_  Members

Posted 05 May 2014 - 04:55 PM

Microsoft's C++ compiler has a flag that specifies whether to use the static runtime (/MT) or the dynamic runtime (/MD).

Issues arrise when different libraries / programs use different versions of the runtime (error messages about conflicting symbols as you saw). There seems to be no "standard" on this so you need to be weary which libraries you use because by default they might use the wrong one.

Since it is probably easier for you to just use whichever runtime SDL uses rather than recompile SDL to match your program we are going to have to add this flag to the Makefile.

So again, either before or after the /link flag (I think it is after because it seems to be a linker option, but not 100% sure), you need to add either /MT or /MD depending on what SDL uses.
You should also remove the NODEFAULTLIB:msvcrt.lib flag since it should hopefully be using the same runtime now

Edited by Karsten_, 05 May 2014 - 05:01 PM.

http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

### #7Lith  Members

Posted 06 May 2014 - 12:12 PM

Microsoft's C++ compiler has a flag that specifies whether to use the static runtime (/MT) or the dynamic runtime (/MD).

Issues arrise when different libraries / programs use different versions of the runtime (error messages about conflicting symbols as you saw). There seems to be no "standard" on this so you need to be weary which libraries you use because by default they might use the wrong one.

Since it is probably easier for you to just use whichever runtime SDL uses rather than recompile SDL to match your program we are going to have to add this flag to the Makefile.

So again, either before or after the /link flag (I think it is after because it seems to be a linker option, but not 100% sure), you need to add either /MT or /MD depending on what SDL uses.
You should also remove the NODEFAULTLIB:msvcrt.lib flag since it should hopefully be using the same runtime now

It builds! (And runs without any problems first try)

Thanks for all your help. I'll try to commit all this to memory to get out of similar situations in the future.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.