Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

_sprintf already defined

Status
Not open for further replies.

marksarnold

Programmer
Feb 5, 2005
5
US
I have a problem with VC++ 6:
I have a static library project and an application project that I want to use the library in.
The library is called loglib, the application logtest.

Compiling the library in its own workspace works fine.
Compiling the app in the app-workspace made problems because it didnt find the library's lib file. So I did "Insert Project into Workspace..." and added the lib project. Then I added the lib src path into the include path and added the dependency in "Project"->Dependencies".

This worked for a while, until I tried using printf in the library's code. This gives me:
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: _sprintf already defined in libcd.lib(sprintf.obj)

I have no clue how to fix this...

The app has been already using printf, so that might be the problem, but I dont know how to get this to work...
Just in case this has anything to do withit, I also get 3 warnings form the linker... Here is the entire output:

Linking...
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: _sprintf already defined in libcd.lib(sprintf.obj)
LINK : warning LNK4098: defaultlib "mfc42d.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "mfcs42d.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/LibTestStatic.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

Any ideas?

Thanks a lot,

MARK
 
What sort of error messages do you get if you don't include "libcd.lib".

It seems to me you grabbed a libc just to make some other error message go away (rather than fixing the actual problem).

> _sprintf already defined in libcd.lib(sprintf.obj)
Why do I get the feeling that this is someone elses "libc", which contains most of what Microsoft's msvcrtd.lib also contains (being as it is a "libc" for VC++).

--
 
Actually, the settings are the default settings the way VC++ created the project. I have done Java for the last 7 years, so I am totally out of shape in C++ world... I used to do c++, but never really went into this Windows and VC++ mess.
That's why I did not change anything in these settings - I was hoping VC++ would do the right thing for me...
I guess it might have to do with the fact that I am throwing 2 different kinds of projects into the same workspace...
Not sure how this should usually be done...

I noticed that the two projects use different /Mx settings - one uses MLd, the MDd, and it seems that's what causes the problem. If I change this to be the same for the two, the error goes away, but I get other errors (undefined symbols) - no matter if I use MDd, MLd, or MTd.

Is there a better way to make one project use the other's library without actually importing both of them in the same workspace? Would that fix my problem?
Thanks,

MARK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top