Libraries linkage errors make me CRAYZEEE  
Author Message
spree





PostPosted: Visual C++ Language, Libraries linkage errors make me CRAYZEEE Top

Hey all, I"m frustrated from working with Visual C++ and libraries :/

I am developing my MFC based project, for which I wanted to add a log system to track my bugs and error msg and etc.,

I have created a static library project and created my Log class:


Visual C++15  

 
 
einaros





PostPosted: Visual C++ Language, Libraries linkage errors make me CRAYZEEE Top

Make sure that your .exe project and all static libraries link the same runtime library. For debug build, all projects should e.g. use "multi-threaded debug", and for release build, all should use "multi-threaded". The setting can be found in your project properties (ALT+F7) -> configuration properties -> c/c++ -> code generation.

 
 
spree





PostPosted: Visual C++ Language, Libraries linkage errors make me CRAYZEEE Top

it is already set to multi-threaded mod, and these projects are in the same solution.

Is there a way to "hide" the inclusion of <iostream> so only the log project can see it

 


 
 
einaros





PostPosted: Visual C++ Language, Libraries linkage errors make me CRAYZEEE Top

it is already set to multi-threaded mod, and these projects are in the same solution.

Is there a way to "hide" the inclusion of <iostream> so only the log project can see it

Make sure that only the source files which need the iostream header, includes the iostream header. You should also be very careful letting the .exe project include files from the static library, and under no circumstances should you go the other way (static library including headers from the .exe proj).

By multi-threaded I assume you mean that neither of your projects use the "* dll" option for the runtime library



 
 
spree





PostPosted: Visual C++ Language, Libraries linkage errors make me CRAYZEEE Top

Make sure that only the source files which need the iostream header, includes the iostream header.

But how do I accomplish this when at the declaration of my log class I have to declar an ostream object

class Log

{

std::ofstream file;

...

 
 
einaros





PostPosted: Visual C++ Language, Libraries linkage errors make me CRAYZEEE Top


But how do I accomplish this when at the declaration of my log class I have to declar an ostream object

In some cases you simply cannot get around it; the definition simply has to be present. With the STL, this will generally not produce errors such as the one noted in your initial post.


And I do use dll's but staticly linked from the complier ( pragma comment(lib,"mydll.lib") ... )

That wasn't what I meant. If you check the runtime library setting in the Project properties -> Configuration properties -> C/C++ -> Code generation, you will see that a few of the options use DLL's, while the others use static libraries. You must make sure that all the libraries in your solution either uses the DLLs, or the static libraries. Don't select an "DLL"-option for one project and non-dll for another.



 
 
spree





PostPosted: Visual C++ Language, Libraries linkage errors make me CRAYZEEE Top

I resolved the problem for now by going to the projects properties>linker>input>Ignore Specific Library>msvcrtd.lib

Are there some books or tutorial on the matter of how to correctly use includes :P


 
 
einaros





PostPosted: Visual C++ Language, Libraries linkage errors make me CRAYZEEE Top

For one, I just noticed a post made by Marius Bancila in another thread: http://www.codeguru.com/forum/showthread.php t=296307. Otherwise I'd recommend you to get a good C++ reference book.