Tutorial :Why isn't this library linking with a pragma comment?



Question:

I'm using Fmod in a project I'm working on in Visual C++ 2008. If I include

../fmodapi375win/api/lib/fmodvc.lib  

in Project->Linker->Input, it works fine, but for some reason if I use

#pragma comment(lib,"../fmodapi375win/api/lib/fmodvc.lib")  

instead it works the same as if that line wasn't there: it builds with no linker errors then crashes with a stack overflow from a million access violation exceptions.

What's going on, and how can I fix it so I can define the lib in code?


Solution:1

I don't think you are supposed to provide the .lib in the pragma comment, but, I think the real problem is that you are calling the comment by path. Add the path to your lib search paths, and then just use a

#pragma comment(lib,"fmodvc")  

You are SUPPOSED to be able to use a path in this comment, but are you sure the ..\ path you are using is the correct path during link time? Also make sure you are NOT compiling with the /nodefaultlib...

Let me know if this still does not work. I've used this type of pragma a lot, with great success...

But, now that I'm pretty much trapped in the C# world, I don't get much time to even program in C++ anymore...


Solution:2

Libs could be linked in another order, so symbols are resolved differently.


Solution:3

Are you absolutely certain it's the same lib file in the two instances?

This can get very weird if you miss the fact that there are two versions of a file on your machine. I seriously suggest you search your drive for all occurrences of this file just to do a sanity check.


Solution:4

Set /VERBOSE on the command line of the link. In the GUI, you can do this on the property page of the project -- add to the "Command Line" node under Linker.

Then it will tell you how it resolved each function -- search for a function you know should be in fmodvc.lib.

Another thing to do is to run PROCMON.EXE during the link (pre-filter so that PATH CONTAINS fmodvc.lib) -- then link. It will tell you the exact location it found the file (and if it ever looked for it). Get PROCMON here: http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

Finally, if it's linking, but not loading your library (or resolving the references) -- you might have the option to force the link to succeed set -- you should turn that off. It would be /FORCE in the command line section (like /VERBOSE).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »