Hi, I am trying use SFML in my screensaver (
http://www.moonscreensaver.com ) to make it cross platform.
I am stuck with a linking problem.
I can link ok dynamically ( /MD, /MDd ) but no luck with static link.
I have an include file to take care of the various imports and libs.
In the code, I have only one line for SFML where I create a sf::RenderWindow
// tests done under vs2005 with sfml 1.6
// the line below links OK both statically and dynamically
//sf::RenderWindow *App=NULL;
// the line below gives link errors if linked statically. Links OK with dynamic linking
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Hello World - SFML");
I also tried to exclude the standard conflicting libraries and I got more errors.
I tried all sorts of things (you can see the REMed lines.
I also recompiled from the source the library, but have the same problem.
Any help full ideas?
Thanks !!
This is the include file:
//
// use_sfml.h
//
#if !defined(USE_SFML_H)
#define USE_SFML_H
#pragma message("Compiling: " __FILE__ )
#if !defined(NDEBUG) // debug
#if defined(_DLL)
//#define SFML_DYNAMIC
//#undef SFML_STATIC
#pragma message(__FILE__ ": Linking SFML dynamically/debug")
#pragma comment(lib,"sfml-graphics-d.lib")
//#pragma comment(lib,"sfml-audio-d.lib")
//#pragma comment(lib,"sfml-network-d.lib")
#pragma comment(lib,"sfml-window-d.lib")
#pragma comment(lib,"sfml-system-d.lib")
//#pragma comment(lib,"sfml-main-d.lib")
#else
//#define SFML_STATIC
//#undef SFML_DYNAMIC
#pragma message(__FILE__ ": Linking SFML statically/debug")
#pragma comment(lib,"sfml-system-s-d.lib")
#pragma comment(lib,"sfml-window-s-d.lib")
#pragma comment(lib,"sfml-graphics-s-d.lib")
//#pragma comment(lib,"sfml-audio-s-d.lib")
//#pragma comment(lib,"sfml-network-s-d.lib")
//#pragma comment(lib,"libcmtd.lib")
//#pragma comment(lib,"LIBCPMTD.LIB")
//#pragma comment(linker, "/nodefaultlib:libcmtd.lib")
//#pragma comment(linker, "/nodefaultlib:libcpmtd.lib")
//#pragma comment(linker, "/nodefaultlib:msvcrtd.lib")
//#pragma comment(linker, "/nodefaultlib:msvcprtd.lib")
#endif
#else // release compilation
#if defined(_DLL) // dynamic release
//#define SFML_DYNAMIC
//#undef SFML_STATIC
#pragma message(__FILE__ ": Linking SFML dynamically/release")
#pragma comment(lib,"sfml-graphics.lib")
#pragma comment(lib,"sfml-window.lib")
#pragma comment(lib,"sfml-system.lib")
#else // static release
//#define SFML_STATIC
//#undef SFML_DYNAMIC
#pragma message(__FILE__ ": Linking SFML statically/release")
#pragma comment(lib,"sfml-system-s.lib")
#pragma comment(lib,"sfml-graphics-s.lib")
//#pragma comment(lib,"sfml-audio-s.lib")
//#pragma comment(lib,"sfml-network-s.lib")
#pragma comment(lib,"sfml-window-s.lib")
//#pragma comment(lib,"sfml-main.lib")
//#pragma comment(linker, "/nodefaultlib:libcmt.lib")
//#pragma comment(linker, "/nodefaultlib:LIBCPMT.LIB")
// If you build using /MD compiler option, your program will link with
// http://support.microsoft.com/kb/154753
#pragma comment(linker, "/nodefaultlib:msvcrt.lib")
#pragma comment(linker, "/nodefaultlib:msvcprt.lib")
//#pragma comment(linker, "/nodefaultlib:libc.lib")
#endif
#endif
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
//#include <SFML/Audio.hpp>
//#include <SFML/Network.hpp>
#endif // USE_SFML_H
and this is the output window:
------ Rebuild All started: Project: smScreensaver, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'smScreensaver', configuration 'Debug|Win32'
Compiling...
TmioanTime.cpp
TmioanTextFile.cpp
TmioanStrings.cpp
TmioanScreenWin.cpp
TmioanScreenSaverAbstract.cpp
Compiling: f:\work\c-proj\starmsg9\mioanlib\application\tmioanscreensaverabstract.h
Compiling: f:\work\c-proj\starmsg9\mioanlib\platform\use_sfml.h
f:\work\c-proj\starmsg9\mioanlib\platform\use_sfml.h: Linking SFML statically/debug
TmioanRandom.cpp
TmioanOperatingSystemWin.cpp
TmioanOperatingSystem.cpp
TmioanLogFileV2.cpp
TmioanLog.cpp
TmioanFileSystemWin.cpp
TmioanFileSystem.cpp
TmioanFilename.cpp
TmioanFile.cpp
TmioanErrorCollector.cpp
TmioanDateTime.cpp
starmsgScreensaver.cpp
Compiling: f:\work\c-proj\starmsg9\mioanlib\application\tmioanscreensaverabstract.h
Compiling: f:\work\c-proj\starmsg9\mioanlib\platform\use_sfml.h
f:\work\c-proj\starmsg9\mioanlib\platform\use_sfml.h: Linking SFML statically/debug
Generating Code...
Compiling resources...
Compiling manifest to resources...
Linking...
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in libcpmtd.lib(xlock.obj)
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in libcpmtd.lib(xlock.obj)
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z) already defined in libcpmtd.lib(stdthrow.obj)
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::_Container_base::~_Container_base(void)" (??1_Container_base@std@@QAE@XZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::_Container_base::_Container_base(void)" (??0_Container_base@std@@QAE@XZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: void __thiscall std::_Container_base::_Orphan_all(void)const " (?_Orphan_all@_Container_base@std@@QBEXXZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > & (__cdecl*)(class std::basic_ostream<char,struct std::char_traits<char> > &))" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??$?6DU?$char_traits@D@std@@V?$allocator@D@1@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@@Z) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::substr(unsigned int,unsigned int)const " (?substr@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE?AV12@II@Z) already defined in TmioanFileSystem.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::find_last_of(char const *,unsigned int)const " (?find_last_of@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIPBDI@Z) already defined in TmioanFileSystem.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)" (?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::operator=(char const *)" (??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: int __thiscall std::ios_base::width(int)" (?width@ios_base@std@@QAEHH@Z) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: static bool __cdecl std::char_traits<char>::eq_int_type(int const &,int const &)" (?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: static int __cdecl std::char_traits<char>::eof(void)" (?eof@?$char_traits@D@std@@SAHXZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHD@Z) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: int __thiscall std::ios_base::flags(void)const " (?flags@ios_base@std@@QBEHXZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: int __thiscall std::ios_base::width(void)const " (?width@ios_base@std@@QBEHXZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: bool __thiscall std::ios_base::good(void)const " (?good@ios_base@std@@QBE_NXZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: void __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "bool __cdecl std::uncaught_exception(void)" (?uncaught_exception@std@@YA_NXZ) already defined in libcpmtd.lib(uncaught.obj)
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in starmsgScreensaver.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: void __thiscall std::_Container_base::_Swap_all(class std::_Container_base &)const " (?_Swap_all@_Container_base@std@@QBEXAAV12@@Z) already defined in TmioanOperatingSystem.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "bool __cdecl std::operator==<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,char const *)" (??$?8DU?$char_traits@D@std@@V?$allocator@D@1@@std@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@PBD@Z) already defined in TmioanLogFileV2.obj
msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::size(void)const " (?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ) already defined in starmsgScreensaver.obj
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __invalid_parameter already defined in LIBCMTD.lib(invarg.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __CrtDbgReportW already defined in LIBCMTD.lib(dbgrptw.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in LIBCMTD.lib(stdexcpt.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: "public: __thiscall std::exception::exception(void)" (??0exception@std@@QAE@XZ) already defined in LIBCMTD.lib(stdexcpt.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in LIBCMTD.lib(stdexcpt.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in LIBCMTD.lib(stdexcpt.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _fclose already defined in LIBCMTD.lib(fclose.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _fopen already defined in LIBCMTD.lib(fopen.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _free already defined in LIBCMTD.lib(dbgheap.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _fwrite already defined in LIBCMTD.lib(fwrite.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _fflush already defined in LIBCMTD.lib(fflush.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _exit already defined in LIBCMTD.lib(crt0dat.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _fprintf already defined in LIBCMTD.lib(fprintf.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: ___iob_func already defined in LIBCMTD.lib(_file.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _sprintf already defined in LIBCMTD.lib(sprintf.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __gmtime64 already defined in LIBCMTD.lib(gmtime64.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _abort already defined in LIBCMTD.lib(abort.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _malloc already defined in LIBCMTD.lib(dbgheap.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _fgetc already defined in LIBCMTD.lib(fgetc.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __wassert already defined in LIBCMTD.lib(wassert.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _fseek already defined in LIBCMTD.lib(fseek.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _ftell already defined in LIBCMTD.lib(ftell.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _realloc already defined in LIBCMTD.lib(dbgheap.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _strtol already defined in LIBCMTD.lib(strtol.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _strncmp already defined in LIBCMTD.lib(strncmp.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _ldexp already defined in LIBCMTD.lib(ldexp.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _getenv already defined in LIBCMTD.lib(getenv.obj)
MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _memmove_s already defined in LIBCMTD.lib(memmove_s.obj)
Creating library c:\tmp\StarMsgNew.lib and object c:\tmp\StarMsgNew.exp
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
c:\tmp\StarMsgNew.scr : fatal error LNK1169: one or more multiply defined symbols found
Build log was saved at "file://e:\Temp\smScreensaver-Debug\BuildLog.htm"
smScreensaver - 68 error(s), 1 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========