简体   繁体   中英

Can't link PhysFS into my C++ project under Visual Studio 2010

I'm trying to use PhysFS in my C++ game (using a C++ wrapper ) under Visual Studio 2010, but the linker refuses to link the library.
I built the library as per the INSTALL.txt file and have a physfs.lib in C:\\include\\physfs-2.0.2\\lib\\Debug , but it tells me that it cannot find the symbols. However, it can definitely find the .lib file, since if I change either the library path or the library name, it throws an error.
I'm completely confused by this, can anyone help? Here's my setup:

VC++ Directories->Library Directories

C:\include\glew-1.7.0\lib
C:\include\boost_1_47_0\libs\
C:\include\glfw-2.7.2\lib
C:\include\glfw-2.7.2\lib\win32
C:\include\boost_1_47_0\stage\lib\
c:\include\allegro-5.0.5-msvc-10.0\lib
C:\include\physfs-2.0.2\lib\Debug
$(LibraryPath)

Linker->Input->Additional Dependancies

physfs.lib
glew32d.lib
GLFW.lib
opengl32.lib
allegro-5.0.5-md-debug.lib
allegro_dialog-5.0.5-md-debug.lib
%(AdditionalDependencies)

Build Output

1>------ Build started: Project: Wolfenstein3D2011, Configuration: Debug Win32 ------
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>Wolfenstein3D2011.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_getDirSeparator referenced in function "void __cdecl PhysFS::`dynamic initializer for 'DIR_SEP''(void)" (??__EDIR_SEP@PhysFS@@YAXXZ)
1>PhysFS.obj : error LNK2001: unresolved external symbol __imp__PHYSFS_getDirSeparator
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_permitSymbolicLinks referenced in function "void __cdecl PhysFS::init(char const *,bool)" (?init@PhysFS@@YAXPBD_N@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_getLastError referenced in function "void __cdecl PhysFS::init(char const *,bool)" (?init@PhysFS@@YAXPBD_N@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_init referenced in function "void __cdecl PhysFS::init(char const *,bool)" (?init@PhysFS@@YAXPBD_N@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_deinit referenced in function "void __cdecl PhysFS::deinit(void)" (?deinit@PhysFS@@YAXXZ)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_isInit referenced in function "bool __cdecl PhysFS::isInit(void)" (?isInit@PhysFS@@YA_NXZ)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_supportedArchiveTypes referenced in function "class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __cdecl PhysFS::supportedArchiveTypes(void)" (?supportedArchiveTypes@PhysFS@@YA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@XZ)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_freeList referenced in function "class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __cdecl PhysFS::getCdRomDirs(void)" (?getCdRomDirs@PhysFS@@YA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@XZ)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_getCdRomDirs referenced in function "class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __cdecl PhysFS::getCdRomDirs(void)" (?getCdRomDirs@PhysFS@@YA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@XZ)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_addToSearchPath referenced in function "void __cdecl PhysFS::addToSearchPath(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?addToSearchPath@PhysFS@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_removeFromSearchPath referenced in function "void __cdecl PhysFS::removeFromSearchPath(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?removeFromSearchPath@PhysFS@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_mount referenced in function "void __cdecl PhysFS::mount(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?mount@PhysFS@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_getMountPoint referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl PhysFS::getMountPoint(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?getMountPoint@PhysFS@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_getSearchPath referenced in function "class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __cdecl PhysFS::getSearchPath(void)" (?getSearchPath@PhysFS@@YA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@XZ)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_getUserDir referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __cdecl PhysFS::getUserDir(void)" (?getUserDir@PhysFS@@YAABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_getBaseDir referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __cdecl PhysFS::getBaseDir(void)" (?getBaseDir@PhysFS@@YAABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_getWriteDir referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl PhysFS::getWriteDir(void)" (?getWriteDir@PhysFS@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_setWriteDir referenced in function "void __cdecl PhysFS::setWriteDir(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?setWriteDir@PhysFS@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_setSaneConfig referenced in function "void __cdecl PhysFS::setSaneConfig(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool,bool)" (?setSaneConfig@PhysFS@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00_N1@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_exists referenced in function "bool __cdecl PhysFS::exists(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?exists@PhysFS@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_isDirectory referenced in function "bool __cdecl PhysFS::isDirectory(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?isDirectory@PhysFS@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_isSymbolicLink referenced in function "bool __cdecl PhysFS::isSymbolicLink(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?isSymbolicLink@PhysFS@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_getLastModTime referenced in function "__int64 __cdecl PhysFS::getLastModTime(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?getLastModTime@PhysFS@@YA_JABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_mkdir referenced in function "void __cdecl PhysFS::mkdir(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?mkdir@PhysFS@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_delete referenced in function "void __cdecl PhysFS::remove(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?remove@PhysFS@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_getRealDir referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl PhysFS::getRealDir(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?getRealDir@PhysFS@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_enumerateFiles referenced in function "class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __cdecl PhysFS::enumerateFiles(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?enumerateFiles@PhysFS@@YA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_openAppend referenced in function "public: __thiscall PhysFS::FileDevice::FileDevice(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,enum PhysFS::OpenMode)" (??0FileDevice@PhysFS@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4OpenMode@1@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_openWrite referenced in function "public: __thiscall PhysFS::FileDevice::FileDevice(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,enum PhysFS::OpenMode)" (??0FileDevice@PhysFS@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4OpenMode@1@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_openRead referenced in function "public: __thiscall PhysFS::FileDevice::FileDevice(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,enum PhysFS::OpenMode)" (??0FileDevice@PhysFS@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4OpenMode@1@@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_close referenced in function "public: void __thiscall PhysFS::FileDevice::close(void)" (?close@FileDevice@PhysFS@@QAEXXZ)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_read referenced in function "public: __int64 __thiscall PhysFS::FileDevice::read(char *,__int64)" (?read@FileDevice@PhysFS@@QAE_JPAD_J@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_write referenced in function "public: __int64 __thiscall PhysFS::FileDevice::write(char const *,__int64)" (?write@FileDevice@PhysFS@@QAE_JPBD_J@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_seek referenced in function "public: class std::fpos<int> __thiscall PhysFS::FileDevice::seek(__int64,int)" (?seek@FileDevice@PhysFS@@QAE?AV?$fpos@H@std@@_JH@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_fileLength referenced in function "public: class std::fpos<int> __thiscall PhysFS::FileDevice::seek(__int64,int)" (?seek@FileDevice@PhysFS@@QAE?AV?$fpos@H@std@@_JH@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_tell referenced in function "public: class std::fpos<int> __thiscall PhysFS::FileDevice::seek(__int64,int)" (?seek@FileDevice@PhysFS@@QAE?AV?$fpos@H@std@@_JH@Z)
1>PhysFS.obj : error LNK2019: unresolved external symbol __imp__PHYSFS_flush referenced in function "public: bool __thiscall PhysFS::FileDevice::flush(void)" (?flush@FileDevice@PhysFS@@QAE_NXZ)
1>C:\Users\Lexi\OpenGL\wulfgame\game\Wolfenstein3D2011.exe : fatal error LNK1120: 37 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I eventually (with a few pointers from other people) found out that the problem was CMake automatically targeting the build for PhysFS to a static win64 library, while my project was expecting it to be a shared win32 dll.
I solved the static/shared issue with a reconfigure, but I couldn't find anything that set the machine architecture. (Presumably there is something, but I know nothing of CMake.)
My final solution:

  1. do a clean CMake configure with the options shared only.
  2. in Build->Configuration Manager add Win32 as a platform and disable test_physfs
  3. in phyfs's Project->Properties->Linker->Advanced , set Target Machine to MachineX86 .
  4. in Linker->Command Line , remove /MACHINE:X64 from Additional Options (This one drove me crazy until I found it by chance)

After that, it compiled into a win32 dll that linked perfectly. Woo.

The root problem is this warning at the very top

LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

The compiler here is saying that the chosen C runtime library that your project links with conflicts with the version that is chosen by some / all of your libs. The is apparently causing it to use no standard library and you end up with a stream of linker errors for types defined in it.

You need to pick a single version of the C runtime for all of your libs and this project. Then compile them all against it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM