Skip to content

error: undefined symbol: public: void __cdecl httplib::Client::set_max_timeout(__int64) #2189

@xuboying

Description

@xuboying

Windows Version: Windows 10 Pro 24H2 (Build 26100.4652)
Windows SDK Version:
MSVC Version: 14.43.34808
httplib.h 0.23.1

Minimal code to reproduce the issue:

#include <iostream>
#include "httplib.h"
int main() {
  httplib::Client cli("http://127.0.0.1:8001");
  cli.set_max_timeout(1000);
  auto res = cli.Post("/pause");
  if (res) {
    std::cerr << "OK" << std::endl;
  } else {
    std::cerr << "NOK" << std::endl;
  }
}
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-DUNICODE)
add_definitions(-D_UNICODE)
project(test)
add_executable(
    ${PROJECT_NAME}
    "test.cpp"
)

Either using clang/msvc or native msvc to build the code, the build fails at linking and report set_max_timeout is undefined. As the lib is a header only lib, it's not expected to add some lib in cmake file...
If cli.set_max_timeout(1000); is removed, everything is OK.

More logs:

[build] [2/2 100% :: 5.492] Linking CXX executable test.exe
[build] FAILED: test.exe 
[build] C:\WINDOWS\system32\cmd.exe /C "cd . && C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\clang.exe -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -Xlinker /subsystem:console  -fuse-ld=lld-link CMakeFiles/test.dir/test.obj -o test.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:test.lib -Xlinker /pdb:test.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cd ."
[build] lld-link: error: undefined symbol: public: void __cdecl httplib::Client::set_max_timeout(__int64)
[build] >>> referenced by D:\repos\test_cpphttplib\test.cpp:5
[build] >>>               CMakeFiles/test.dir/test.obj:(main)
[build] clang: error: linker command failed with exit code 1 (use -v to see invocation)
[build] ninja: build stopped: subcommand failed.
[proc] The command: c:\usr\bin\mycmake.exe --build d:/repos/test_cpphttplib/build/Debug --config Debug --target all -j 4 -- exited with code: 1
[driver] Build completed: 00:00:07.504
[build] Build finished with exit code 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions