无法将 PhysFS 链接到我在 Visual Studio 2010 下的C++项目

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

本文关键字:Studio Visual 2010 下的 项目 C++ PhysFS 链接      更新时间:2023-10-16

我正试图在Visual Studio 2010下的C++游戏中使用PhysFS(使用C++包装器),但链接器拒绝链接库
我根据INSTALL.txt文件构建了库,并在C:\include\physfs-2.02\lib\Debug中有一个physfs.lib,但它告诉我找不到符号。但是,它肯定可以找到.lib文件,因为如果我更改库路径或库名称,它就会抛出一个错误
我完全被这个弄糊涂了,有人能帮忙吗?这是我的设置:

VC++目录->库目录

C:includeglew-1.7.0lib
C:includeboost_1_47_0libs
C:includeglfw-2.7.2lib
C:includeglfw-2.7.2libwin32
C:includeboost_1_47_0stagelib
c:includeallegro-5.0.5-msvc-10.0lib
C:includephysfs-2.0.2libDebug
$(LibraryPath)

链接器->输入->附加依赖项

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

生成输出

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:UsersLexiOpenGLwulfgamegameWolfenstein3D2011.exe : fatal error LNK1120: 37 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我最终(用其他人的一些指针)发现问题是CMake自动将PhysFS的构建目标定为静态win64库,而我的项目希望它是一个共享的win32 dll
我通过重新配置解决了静态/共享问题,但找不到任何设置机器架构的东西。(大概有什么,但我对CMake一无所知。)
我的最终解决方案:

  1. 使用仅共享的选项进行干净的CMake配置
  2. Build->Configuration Manager中将Win32添加为平台并禁用test_physfs
  3. 在phyfs的项目->属性->链接器->高级中,将目标机器设置为MachineX86
  4. Linker->命令行中,从附加选项中删除/MACHINE:X64(这个选项让我抓狂,直到我偶然发现它)

之后,它编译成一个完美链接的win32 dll。求爱

根本问题是最顶层的警告

链接:警告LNK4098:defaultlib"MSVCRT"与其他库的使用冲突;使用/NODEFAULTLIB:库

这里的编译器说,您的项目链接的所选C运行库与您的一些/所有库选择的版本冲突。很明显,这导致它没有使用标准库,并且最终会为其中定义的类型带来一连串的链接器错误

您需要为所有的库和这个项目选择一个C运行时的单一版本。然后根据它编译它们。