Linking *.obj file with #pragma directive?
Hello everybody!
Is it possible to link an object file with a #pragma directive to my project? I can add a specified object file in the project settings. But how can I do this dynamically?
I tried something like:
#pragma comment( linker, "foo.obj" )
Of course this doesn't work! Any ideas?
Thx in advance!
[355 byte] By [
Michello] at [2007-11-18 19:13:27]

# 1 Re: Linking *.obj file with #pragma directive?
Do you want to link an obj or a lib or doesn't it matter? In any case, linker is for link-specifc options, whereas lib is for additional .lib files. So the syntax would be:
#pragma comment(lib, "mylib-lib")
Yves M at 2007-11-11 1:18:17 >

# 2 Re: Linking *.obj file with #pragma directive?
Thx for quick response!
No, unfortunately it does matter! I need to link an *.obj file. I already tried #pragma comment( lib, ... ) with this file type, but as I expected, the linker needs a real *.lib file here. Maybe any other suggestion?
# 3 Re: Linking *.obj file with #pragma directive?
Well, the other suggestion is to use a makefile to compile the project or add it to the dependencies. I can't see how you would do that in the code.
Yves M at 2007-11-11 1:20:15 >

# 4 Re: Linking *.obj file with #pragma directive?
Thank you very much for help Yves M!
Instead...
...is it possible to add the corresponding *.cpp file to the project dynamically and to instruct the linker to use the final *.obj file?
Another idea:
Can I create a *.lib file instead of an *.obj file?
# 5 Re: Linking *.obj file with #pragma directive?
The instruction for including a cpp file from code is very simple:
#include "blahblah.cpp"
in another cpp file.
Depending on what it is what you want to achieve, a lib file may indeed be a better idea though. In VC6 you do it by creating a new project and specifying "Win32 static library" as Project type. You'll need to compile this once as Debug and once as Release and link to the appropriate one in your final app, depending on whether you're in Debug or Release mode.
Yves M at 2007-11-11 1:22:17 >
