influxdb-cxx: error LNK2001: unresolved external symbol __declspec(dllimport)

Hello, I am the maintainer of vcpkg. In the process of updating to v0.7.1, I found the following error. After investigation, I found that InfluxDB_EXPORTS was not defined during dynamic linking, which caused it to execute __declspec(dllimport).

TCP.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::InfluxDBException::InfluxDBException(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0InfluxDBException@influxdb@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
UnixSocket.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::InfluxDBException::InfluxDBException(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0InfluxDBException@influxdb@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
InfluxDB.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::InfluxDBException::InfluxDBException(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0InfluxDBException@influxdb@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
InfluxDBFactory.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::InfluxDBException::InfluxDBException(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0InfluxDBException@influxdb@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
HTTP.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::InfluxDBException::InfluxDBException(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0InfluxDBException@influxdb@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
UDP.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::InfluxDBException::InfluxDBException(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0InfluxDBException@influxdb@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
InfluxDB.cxx.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::Point::~Point(void)" (__imp_??1Point@influxdb@@QEAA@XZ) referenced in function "public: void * __cdecl influxdb::Point::`scalar deleting destructor'(unsigned int)" (??_GPoint@influxdb@@QEAAPEAXI@Z)
BoostSupport.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::Point::~Point(void)" (__imp_??1Point@influxdb@@QEAA@XZ)
InfluxDB.cxx.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::Point::Point(class influxdb::Point &&)" (__imp_??0Point@influxdb@@QEAA@$$QEAV01@@Z) referenced in function "public: static void __cdecl std::_Default_allocator_traits<class std::allocator<class influxdb::Point> >::construct<class influxdb::Point,class influxdb::Point>(class std::allocator<class influxdb::Point> &,class influxdb::Point * const,class influxdb::Point &&)" (??$construct@VPoint@influxdb@@V12@@?$_Default_allocator_traits@V?$allocator@VPoint@influxdb@@@std@@@std@@SAXAEAV?$allocator@VPoint@influxdb@@@1@QEAVPoint@influxdb@@$$QEAV34@@Z)
BoostSupport.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::Point::Point(class influxdb::Point &&)" (__imp_??0Point@influxdb@@QEAA@$$QEAV01@@Z)
  Hint on symbols that are defined and could potentially match:
    "__declspec(dllimport) public: __cdecl influxdb::Point::Point(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0Point@influxdb@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
TCP.cxx.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl influxdb::InfluxDBException::~InfluxDBException(void)" (??1InfluxDBException@influxdb@@UEAA@XZ)
UnixSocket.cxx.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl influxdb::InfluxDBException::~InfluxDBException(void)" (??1InfluxDBException@influxdb@@UEAA@XZ)
InfluxDB.cxx.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl influxdb::InfluxDBException::~InfluxDBException(void)" (??1InfluxDBException@influxdb@@UEAA@XZ)
InfluxDBFactory.cxx.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl influxdb::InfluxDBException::~InfluxDBException(void)" (??1InfluxDBException@influxdb@@UEAA@XZ)
HTTP.cxx.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl influxdb::InfluxDBException::~InfluxDBException(void)" (??1InfluxDBException@influxdb@@UEAA@XZ)
UDP.cxx.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl influxdb::InfluxDBException::~InfluxDBException(void)" (??1InfluxDBException@influxdb@@UEAA@XZ)
TCP.cxx.obj : error LNK2001: unresolved external symbol "public: __cdecl influxdb::InfluxDBException::InfluxDBException(class influxdb::InfluxDBException const &)" (??0InfluxDBException@influxdb@@QEAA@AEBV01@@Z)
UnixSocket.cxx.obj : error LNK2001: unresolved external symbol "public: __cdecl influxdb::InfluxDBException::InfluxDBException(class influxdb::InfluxDBException const &)" (??0InfluxDBException@influxdb@@QEAA@AEBV01@@Z)
InfluxDB.cxx.obj : error LNK2001: unresolved external symbol "public: __cdecl influxdb::InfluxDBException::InfluxDBException(class influxdb::InfluxDBException const &)" (??0InfluxDBException@influxdb@@QEAA@AEBV01@@Z)
InfluxDBFactory.cxx.obj : error LNK2001: unresolved external symbol "public: __cdecl influxdb::InfluxDBException::InfluxDBException(class influxdb::InfluxDBException const &)" (??0InfluxDBException@influxdb@@QEAA@AEBV01@@Z)
HTTP.cxx.obj : error LNK2001: unresolved external symbol "public: __cdecl influxdb::InfluxDBException::InfluxDBException(class influxdb::InfluxDBException const &)" (??0InfluxDBException@influxdb@@QEAA@AEBV01@@Z)
UDP.cxx.obj : error LNK2001: unresolved external symbol "public: __cdecl influxdb::InfluxDBException::InfluxDBException(class influxdb::InfluxDBException const &)" (??0InfluxDBException@influxdb@@QEAA@AEBV01@@Z)
Point.cxx.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static int influxdb::Point::floatsPrecision" (__imp_?floatsPrecision@Point@influxdb@@2HA) referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl influxdb::Point::getFields(void)const " (?getFields@Point@influxdb@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
HTTP.cxx.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::Transport::Transport(void)" (__imp_??0Transport@influxdb@@QEAA@XZ) referenced in function "public: __cdecl influxdb::transports::HTTP::HTTP(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0HTTP@transports@influxdb@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
UDP.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::Transport::Transport(void)" (__imp_??0Transport@influxdb@@QEAA@XZ)
TCP.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::Transport::Transport(void)" (__imp_??0Transport@influxdb@@QEAA@XZ)
UnixSocket.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::Transport::Transport(void)" (__imp_??0Transport@influxdb@@QEAA@XZ)
HTTP.cxx.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl influxdb::Transport::~Transport(void)" (__imp_??1Transport@influxdb@@UEAA@XZ) referenced in function "int `public: __cdecl influxdb::transports::HTTP::HTTP(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)'::`1'::dtor$0" (?dtor$0@?0???0HTTP@transports@influxdb@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z@4HA)
UDP.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl influxdb::Transport::~Transport(void)" (__imp_??1Transport@influxdb@@UEAA@XZ)
TCP.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl influxdb::Transport::~Transport(void)" (__imp_??1Transport@influxdb@@UEAA@XZ)
UnixSocket.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl influxdb::Transport::~Transport(void)" (__imp_??1Transport@influxdb@@UEAA@XZ)
BoostSupport.cxx.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::Point::Point(class influxdb::Point const &)" (__imp_??0Point@influxdb@@QEAA@AEBV01@@Z) referenced in function "public: static void __cdecl std::_Default_allocator_traits<class std::allocator<class influxdb::Point> >::construct<class influxdb::Point,class influxdb::Point &>(class std::allocator<class influxdb::Point> &,class influxdb::Point * const,class influxdb::Point &)" (??$construct@VPoint@influxdb@@AEAV12@@?$_Default_allocator_traits@V?$allocator@VPoint@influxdb@@@std@@@std@@SAXAEAV?$allocator@VPoint@influxdb@@@1@QEAVPoint@influxdb@@AEAV34@@Z)
  Hint on symbols that are defined and could potentially match:
    "__declspec(dllimport) public: __cdecl influxdb::Point::Point(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0Point@influxdb@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
UDP.cxx.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl influxdb::Transport::query(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?query@Transport@influxdb@@UEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV34@@Z)
TCP.cxx.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl influxdb::Transport::query(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?query@Transport@influxdb@@UEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV34@@Z)
UnixSocket.cxx.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl influxdb::Transport::query(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?query@Transport@influxdb@@UEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV34@@Z)
UDP.cxx.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl influxdb::Transport::execute(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?execute@Transport@influxdb@@UEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV34@@Z)
TCP.cxx.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl influxdb::Transport::execute(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?execute@Transport@influxdb@@UEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV34@@Z)
UnixSocket.cxx.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl influxdb::Transport::execute(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?execute@Transport@influxdb@@UEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV34@@Z)
UDP.cxx.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl influxdb::Transport::createDatabase(void)" (?createDatabase@Transport@influxdb@@UEAAXXZ)
TCP.cxx.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl influxdb::Transport::createDatabase(void)" (?createDatabase@Transport@influxdb@@UEAAXXZ)
UnixSocket.cxx.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl influxdb::Transport::createDatabase(void)" (?createDatabase@Transport@influxdb@@UEAAXXZ)
UDP.cxx.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl influxdb::Transport::setProxy(class influxdb::Proxy const &)" (?setProxy@Transport@influxdb@@UEAAXAEBVProxy@2@@Z)
TCP.cxx.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl influxdb::Transport::setProxy(class influxdb::Proxy const &)" (?setProxy@Transport@influxdb@@UEAAXAEBVProxy@2@@Z)

UnixSocket.cxx.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl influxdb::Transport::setProxy(class influxdb::Proxy const &)" (?setProxy@Transport@influxdb@@UEAAXAEBVProxy@2@@Z)

src\InfluxDB.dll : fatal error LNK1120: 13 unresolved externals

ninja: build stopped: subcommand failed.

For further confirmation, I abandoned vcpkg, built your library separately, and found the same error. See the attachment for details: error.log

Related PR: https://github.com/microsoft/vcpkg/pull/31145

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 24 (12 by maintainers)

Most upvoted comments

Hi there! I’m a maintainer from Conan Center and currently reviewing the PR to add this library into our repository and facing the same issue.

Upon investigation, the issue is caused by the InfluxDB library target being composed of three separate object libraries

add_library(InfluxDB
    $<TARGET_OBJECTS:InfluxDB-Core>
    $<TARGET_OBJECTS:InfluxDB-Internal>
    $<TARGET_OBJECTS:InfluxDB-BoostSupport>
    )
add_library(InfluxData::InfluxDB ALIAS InfluxDB)

The generate_export_header(InfluxDB) does indeed generate the header file, which causes CMake to pass the relevant macro to the InfluxDB target. However, because this library has no sources of its own - the sources for InfluxDB-Core, InfluxDB-Internal and InfluxDB-BoostSupport are being compiled without the relevant macro needed - so nothing gets really exported when building the shared library, resulting in the errors.

So the behaviour of generate_export_header(InfluxDB) is not affecting the actual translation units where the macro defines are needed.

Simular issues are reported:

however no solution is provided.

My recommendation based on looking at https://github.com/offa/influxdb-cxx/blob/master/src/CMakeLists.txt would be perhaps to have a single target with all the sources, rather than separate object targets - given how few files are involved, and the conditionals can still be kept.

@MonicaLiu0311 is this solved for you?

Still the same error.

–> Doing a Git Bisect to determine the commit which may have introduced the linker issues. Let me know if you need some help here.

I found the commit where the error occurred for the first time: https://github.com/offa/influxdb-cxx/commit/4f1f45ed5cf440cea25de2a6afb5be7e00970678

4f1f45ed5cf440cea25de2a6afb5be7e00970678
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[4f1f45ed5cf440cea25de2a6afb5be7e00970678] Replace curl with cpr (#93)

Just to be on the safe side, I also tried the commits before and after it to make sure it was the culprit.