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

I've been trying to build my app (with wxWidgets) using Clang (with MSVC libraries). But I keep getting these linking errors. I used to build the app using minGW and it worked just fine.

These are the errors:

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

I have wxWidgets v3.1.5, Clang v13.0.1 and MSVC v143

I am using this 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)

I've tried this on Windows 11 as well as Windows 10, both with the same outcome.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source