Skip to main content
GameDev.net gamedev.net
🔒 Locked

What's the difference between "Add to project" and "#pragma comment(lib,"mylib.lib")"

Started by kimryo Jul 14, 2005 at 4:30 AM 8 replies 13k views
Original Post
kimryo
kimryo
My static lib's CRT links to libcmt.lib; When use in MFC project(CRT links to msvcrt.dll,both are multi-thread lib), if use "Add to project" to import lib file,it's ok; But use "#pragma comment(lib,"mylib.lib")",I got many CRT symbol redefine linking error...So strange,why???? Could any one tell??Thanks in advance~
God create the world,we create another one.-Reference
kimryo
kimryo
Oh,my god~I've got panic~~~It's already 21 views,but no response~~...
God create the world,we create another one.-Reference
Oxyacetylene
Oxyacetylene
My bet is that the lib you're including with #pragma comment is linked with a different version of the libraries.

For example, your project might be linking to the single threaded versions of the runtime libraries, while the library is linking to the multithreaded versions. Make sure they're the same.

If you're using Visual C++, then the setting is under Project Properties , C/C++, Runtime Library.
kimryo
kimryo
Quote:
Original post by Oxyacetylene
My bet is that the lib you're including with #pragma comment is linked with a different version of the libraries.

For example, your project might be linking to the single threaded versions of the runtime libraries, while the library is linking to the multithreaded versions. Make sure they're the same.

If you're using Visual C++, then the setting is under Project Properties , C/C++, Runtime Library.


No,exactlly there is only 1 .lib file.Maybe you could do a test as I said.
e.g. using zlib in a MFC project.
God create the world,we create another one.-Reference
Kwizatz
Kwizatz
The pragma approach is Microsoft (and probably Intel) compiler specific, if you want your code to be portable, you should either add the lib to the project or add the lib to the libraries variable on the project linking options.
Shannon Barber
Shannon Barber
You shouldn't link in the CRT to a library, let the main app link it.

#pragma comment(lib, ...) is an MS extention that's the same as adding the library to your link list.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
kimryo
kimryo
Quote:
Original post by Kwizatz
The pragma approach is Microsoft (and probably Intel) compiler specific, if you want your code to be portable, you should either add the lib to the project or add the lib to the libraries variable on the project linking options.


oh...my god...
God create the world,we create another one.-Reference
Fruny
Fruny
Quote:
Original post by Kwizatz
The pragma approach is Microsoft (and probably Intel) compiler specific, if you want your code to be portable, you should either add the lib to the project or add the lib to the libraries variable on the project linking options.


The rule is that unrecognized pragmas must be ignored. The problem is that two compilers could still interpret the same pragma in different ways.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Kwizatz
Kwizatz
Quote:
Original post by Fruny
Quote:
Original post by Kwizatz
The pragma approach is Microsoft (and probably Intel) compiler specific, if you want your code to be portable, you should either add the lib to the project or add the lib to the libraries variable on the project linking options.


The rule is that unrecognized pragmas must be ignored. The problem is that two compilers could still interpret the same pragma in different ways.


Right, I remember having problems with "#pragma once" when I started using GCC (2.95 or so) it used to ignore them, and hell broke lose.

My bad. [smile]
Enigma
Enigma
Quote:
Original post by Fruny
The rule is that unrecognized pragmas must be ignored. The problem is that two compilers could still interpret the same pragma in different ways.

I'd love to see some other compilers implement #pragma curious_george, #pragma gpfault prettyplease and #pragma keeka!

Enigma

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.