Jump to content

  • Log In with Google      Sign In   
  • Create Account


Linking libraries in VS 2012 (Express)


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.

  • You cannot reply to this topic
5 replies to this topic

#1 Cromulent   Members   -  Reputation: 349

Like
0Likes
Like

Posted 03 November 2013 - 12:07 PM

I'm a Unix programmer. I've never really programmed on Windows before and as such Visual Studio is new beast for me. I'm finding some simple things pretty hard to do when compared to how easy it is on Unix. It seems that in Visual Studio you need to set the correct search paths by going to Project > Project Properties and then setting the relevant settings in VC++ Directories but even though I have set the correct directories for searching the linker can't find my compiled versions of Boost 1.54 and gives the following error:

 

Error 1 error LNK1104: cannot open file 'libboost_program_options-vc110-mt-gd-1_54.lib'
 
yet when I go and look in my Boost lib directory I see boost_program_options-vc110-mt-gd-1_54.lib and it should be discoverable. VC++ certainly finds the header files correctly it is just the DLLs and the LIB files that it can't find. Anyone got any suggestions as to what I am doing wrong here? Is there another setting I am missing at all?


Sponsor:

#2 Adyrhan   Members   -  Reputation: 212

Like
2Likes
Like

Posted 03 November 2013 - 12:28 PM

I'm almost in the same situation as you, coming from a Unix environment to develop games in Windows. If you go to Project > Project Properties > Linker >  Input > Additional libraries, you can specifiy more explicitly which libraries your project needs. That is how I'm getting the linker to properly work. Also you will need to put the directory where those libraries are, either in Linker > Additional library directories or in VC++ Directories > Directories for library search

Hope it helps !


Edited by Adyrhan, 03 November 2013 - 12:32 PM.


#3 Cromulent   Members   -  Reputation: 349

Like
0Likes
Like

Posted 03 November 2013 - 01:38 PM

I'm almost in the same situation as you, coming from a Unix environment to develop games in Windows. If you go to Project > Project Properties > Linker >  Input > Additional libraries, you can specifiy more explicitly which libraries your project needs. That is how I'm getting the linker to properly work. Also you will need to put the directory where those libraries are, either in Linker > Additional library directories or in VC++ Directories > Directories for library search

Hope it helps !

 

Thanks for the help. I've got my stuff linking statically but the dynamic linking is still eluding me at the moment. I'll have another play around with it when I have some more free time.



#4 Ryan_001   Prime Members   -  Reputation: 1304

Like
1Likes
Like

Posted 03 November 2013 - 04:12 PM

There's a few things that you might be doing wrong, not sure exactly which one is causing you issues...

 

First is that setting directories by going to Project > Project properties probably isn't doing what you think its doing.  That will set the directories for only that single project.  If you want to set it for all your projects you have to go to the Propery Manager window.  There you'll find some files, the one you're looking for is Microsoft.Cpp.Win32.user (there's also a Microsoft.Cpp.Win64.user for 64 bit).  Right click on it, go to properties, and any properties you change in there will become the 'default' for all projects.

 

When linking to boost, you don't need to specify the libraries individually.  The header files automatically link in the appropriate .lib files as needed (probably through judicious of #pragma's in the headers I imagine).  So as long as your lib dir is set correctly you should be fine.

 

In my situation (using VS2012 express as well) in Microsoft.Cpp.Win32.user I added 'D:\Programming\boost\libx86' to my Library directory which is where the 32 bit libs sit on my system, and that was all that was needed.

 

Not sure if that solves your problem, but perhaps it'll help.



#5 Karsten_   Members   -  Reputation: 1551

Like
2Likes
Like

Posted 04 November 2013 - 04:37 AM

We use the Microsoft C++ compiler in much the same way as GCC on Windows. The following is a few examples from our Makefiles if it helps (personally I find the documentation for commandline MSVC usage to be really lacking!).


.cpp unit to .obj
cl.exe /nologo /EHsc -c -I..\..\..\import\msvc\include -I..\..\ $(CXXFLAGS) /Fo$@ $<

relevant .obj files to static lib. Here we are also including the GLEW32s.lib into our static lib so it doesnt need to be linked in during the final step.
lib.exe /OUT:..\..\lib\mutiny.lib $(OBJ) ..\..\import\msvc\lib\GLEW32s.lib

Link other .obj files to final .exe and then link against required libs and our static lib we generated in the step above
link.exe /SUBSYSTEM:WINDOWS /OUT:$(BIN) $(OBJ) /LIBPATH:..\..\..\import\msvc\lib /LIBPATH:..\..\..\lib OpenGL32.lib GLU32.lib SDLmain.lib SDL.lib mutiny.lib $(LDFLAGS)

The main thing to notice is the /LIBPATH parameters are similar to -L on gcc. Also note that there is no need for -l, you just specify the name of the lib (including the .lib suffix).

Edited by Karsten_, 04 November 2013 - 04:44 AM.

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


#6 Cromulent   Members   -  Reputation: 349

Like
0Likes
Like

Posted 05 November 2013 - 12:25 AM

We use the Microsoft C++ compiler in much the same way as GCC on Windows. The following is a few examples from our Makefiles if it helps (personally I find the documentation for commandline MSVC usage to be really lacking!).


.cpp unit to .obj

cl.exe /nologo /EHsc -c -I..\..\..\import\msvc\include -I..\..\ $(CXXFLAGS) /Fo$@ $<
relevant .obj files to static lib. Here we are also including the GLEW32s.lib into our static lib so it doesnt need to be linked in during the final step.
lib.exe /OUT:..\..\lib\mutiny.lib $(OBJ) ..\..\import\msvc\lib\GLEW32s.lib
Link other .obj files to final .exe and then link against required libs and our static lib we generated in the step above
link.exe /SUBSYSTEM:WINDOWS /OUT:$(BIN) $(OBJ) /LIBPATH:..\..\..\import\msvc\lib /LIBPATH:..\..\..\lib OpenGL32.lib GLU32.lib SDLmain.lib SDL.lib mutiny.lib $(LDFLAGS)
The main thing to notice is the /LIBPATH parameters are similar to -L on gcc. Also note that there is no need for -l, you just specify the name of the lib (including the .lib suffix).

 

 

Thank you for that. I much prefer using the command line options so that was incredibly useful.

 

I think I've pretty much got to grips with linking on Windows. Thanks for everyone's help.






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.



PARTNERS