在 Windows 上使用 Clang 构建 wxWidgets 时对 std::streambuf 方法的未定义引用

Undefined references to std::streambuf methods when building wxWidgets with Clang on Windows

提问人:Albert121 提问时间:3/23/2022 最后编辑:Albert121 更新时间:3/23/2022 访问量:324

问:

我一直在尝试使用 Clang(使用 MSVC 库)构建我的应用程序(使用 wxWidgets)。但是我不断收到这些链接错误。我曾经使用 minGW 构建应用程序,它运行良好。

这些是错误:

graphics.o : error LNK2019: unresolved external symbol "__declspec(dllimport) protected: void __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::setp(char *,char *,char *)" (__imp_?setp@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEAAXPEAD00@Z) referenced in function "protected: virtual in
t __cdecl std::basic_stringbuf<char,struct std::char_traits<char>,class std::allocator<char> >::overflow(int)" (?overflow@?$basic_stringbuf@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@MEAAHH@Z)
graphics.o : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::locale __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::getloc(void)const " (__imp_?getloc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEBA?AVlocale@2@XZ) referenced in function "public: clas 
s std::basic_filebuf<char,struct std::char_traits<char> > * __cdecl std::basic_filebuf<char,struct std::char_traits<char> >::open(char const *,int,int)" (?open@?$basic_filebuf@DU?$char_traits@D@std@@@std@@QEAAPEAV12@PEBDHH@Z)
shaders.o : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::locale __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::getloc(void)const " (__imp_?getloc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEBA?AVlocale@2@XZ)
clang++: error: linker command failed with exit code 1120 (use -v to see invocation)
graphics.o : error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::snextc(void)" (__imp_?snextc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAAHXZ) referenced in function "class std::basic_istream<char,struct std::c 
har_traits<char> > & __cdecl std::getline<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_istream<char,struct std::char_traits<char> > &&,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,char)" (??$getline@DU?$char_traits@D@std@@V?$all 
ocator@D@2@@std@@YAAEAV?$basic_istream@DU?$char_traits@D@std@@@0@$$QEAV10@AEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@D@Z)
shaders.o : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::snextc(void)" (__imp_?snextc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAAHXZ)
make: *** [main.exe] Error 1120
shaders.o : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::fpos<struct _Mbstatet> __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::pubseekoff(__int64,int,int)" (__imp_?pubseekoff@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAA?AV?$fpos@U_Mbstatet@@@2 
@_JHH@Z) referenced in function "public: class std::basic_istream<char,struct std::char_traits<char> > & __cdecl std::basic_istream<char,struct std::char_traits<char> >::seekg(__int64,int)" (?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@_JH@Z)
shaders.o : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::sgetn(char *,__int64)" (__imp_?sgetn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAA_JPEAD_J@Z) referenced in function "public: class std::basic_ 
istream<char,struct std::char_traits<char> > & __cdecl std::basic_istream<char,struct std::char_traits<char> >::read(char *,__int64)" (?read@?$basic_istream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@PEAD_J@Z)
.\build\main.exe : fatal error LNK1120: 5 unresolved externals

我有 wxWidgets v3.1.5、Clang v13.0.1 和 MSVC v143

我正在使用这个makefile:

CXX := clang++
CXXFLAGS := -Winvalid-pch -Wall -Wextra --std=c++17
CXXFLAGS := -DWXUSINGDLL -D_UNICODE -D__WXMSW__ -DNDEBUG

OUTPUT := main.exe

SRC_DIR = ./src
BUILD_DIR = ./build

CXXFLAGS += -isystem./include/msvc -isystem./include
LDFLAGS := -L./lib/vc_x64_dll
LDFLAGS += -L./lib/glew
LDFLAGS +=  -lopengl32
LDFLAGS += -lglew32

SOURCES := $(wildcard $(SRC_DIR)/*.cpp)
OBJS := $(SOURCES:%.cpp=%.o)

DEPS := $(wildcard $(SRC_DIR)/*.hpp)

all: $(OUTPUT)

$(OUTPUT): $(OBJS)
    @echo linking...
    @$(CXX) -o ./build/$@ $(OBJS) $(LDFLAGS)

.PHONY: all

%.o: %.cpp $(DEPS)
    @echo $(CXX) -c $<
    @$(CXX) $< -c -o $@ $(CXXFLAGS)

我在 Windows 11 和 Windows 10 上尝试过这个,结果都是一样的。

C++ Windows Clang wxWidgets 链接器错误

评论

0赞 Igor 3/23/2022
@Albert21,价值是什么?LDFLAGS
0赞 Community 3/23/2022
请澄清您的具体问题或提供其他详细信息以准确说明您的需求。正如目前所写的那样,很难确切地说出你在问什么。
0赞 Albert121 3/23/2022
@Igor我忘了将第一次提及的赋值运算符更改为赋值运算符。以前,我将此链接器标志用于 minGW:。LDFLAGS := -Wl,-subsystem,windows
0赞 Igor 3/23/2022
@Albert121,所以它现在编译了?
0赞 Albert121 3/24/2022
@Igor 不,makefile 是这样的。我只是忘了改成.但这没有任何区别 - 添加到以前未设置为任何值的字符串与设置字符串相同。+=:=

答: 暂无答案