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

Stuart P. Bentley picture Stuart P. Bentley · Feb 17, 2009 · Viewed 13.8k times · Source

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?

Answer

LarryF picture LarryF · Mar 20, 2009

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...