Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error LNK2001: unresolved external symbol __declspec(dllimport) #194

Open
MonicaLiu0311 opened this issue Apr 27, 2023 · 25 comments · May be fixed by #245
Open

error LNK2001: unresolved external symbol __declspec(dllimport) #194

MonicaLiu0311 opened this issue Apr 27, 2023 · 25 comments · May be fixed by #245

Comments

@MonicaLiu0311
Copy link

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: microsoft/vcpkg#31145

@offa
Copy link
Owner

offa commented Apr 27, 2023

Thanks for reporting. All of the import / export handling is done through generate_export_header(), which generates influxdb_export.h and related macros. The docs don't mention any additional settings or defines needed for MSVC.

I don't have a MSVC around to check the generated file, but I assume it should look similar to GCC / Clang. The attached log contains many other errors, could they lead to the linker issues listed above?

@MonicaLiu0311
Copy link
Author

could they lead to the linker issues listed above?

  • VS 2022
  • Win 10

Yes, when I using the way influxdb-cxx#installation to build 0.7.1, LNK2001 and LNK2019 appeared, but the previous 0.6.7 was built successfully.

@offa
Copy link
Owner

offa commented Apr 28, 2023

Doing a quick diff between both version I can't see any reason for the linker issues, the export related settings haven't changed. Only SOVERSION introduced with 0.7.0, which seems to work different on Windows.

Can you bisect the commit introducing the linker issues?

@MonicaLiu0311
Copy link
Author

Can you bisect the commit introducing the linker issues?

Sorry I'm late (on vacation), do you mean that you want me to separate error LNK2001 and LNK2019 into two issues? But they are all caused by the same reason.

If I misunderstood something, please correct me.

@offa
Copy link
Owner

offa commented May 9, 2023

Sorry I'm late (on vacation), do you mean that you want me to separate error LNK2001 and LNK2019 into two issues?

No, the issue is fine :-)

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

@MonicaLiu0311
Copy link
Author

--> 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: 4f1f45e

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.

@offa
Copy link
Owner

offa commented May 11, 2023

Thanks!

So introducing neither the SOVERSION is the reason, nor are there any import / export related changes. The commit replaces one library with another without touching much code (except HTTP).

I don't understand how this affects, eg. TCP not finding InfluxDBExceptionsymbols – both not modified:

TCP.cxx.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl influxdb::InfluxDBException::InfluxDBException(class std::basic_string<char,struct std::char_traits,class std::allocator > const &)"

@MonicaLiu0311
Copy link
Author

I don't understand how this affects

I don't have a clue either🙁

@offa
Copy link
Owner

offa commented May 22, 2023

Could the changes to src/CMakeList.txt in the mentioned commit cause the problem? Maybe MSVC doesn't cope with object libraries?

@MonicaLiu0311
Copy link
Author

Could the changes to src/CMakeList.txt in the mentioned commit cause the problem?

I'm not sure...but I'd be happy to verify your patch if you have an idea.

Maybe MSVC doesn't cope with object libraries?

In general, when using object libraries as dependencies of other targets, MSVC will automatically include the object files into the final executable or library during the linking phase.
But why does it affect the macro definition in influxdb_export.h?

@offa
Copy link
Owner

offa commented Jun 5, 2023

But why does it affect the macro definition in influxdb_export.h?

Is there even a difference between the broken commit and the commit before?

@fmvin
Copy link

fmvin commented Sep 9, 2023

I have same errors if trying to build from master on Windows Server 2019 and MSVC 2022. The reason why I'm trying to build influxdb-cxx by myself is that the vcpkg package influxdb-cxx throws an exception on any query or connection by udp/tcp transport. It looks like this is boost related issue.

@MonicaLiu0311 Do you observe the same problem with queries to databases?

@offa
Copy link
Owner

offa commented Sep 10, 2023

The reason why I'm trying to build influxdb-cxx by myself is that the vcpkg package influxdb-cxx throws an exception on any query or connection by udp/tcp transport. It looks like this is boost related issue.

Sounds like it was built without boost.

@fmvin
Copy link

fmvin commented Sep 10, 2023

Sounds like it was built without boost.

I suppose it is built with boost. In other case influxdb-cxx throws a meaningful exceptions like Query requires Boost. In my case the program just crashes with abort() has been called (not exception as mentioned above).

@fmvin
Copy link

fmvin commented Sep 10, 2023

@offa, anyway I can't build the library on Windows. Could you please point me in the right direction.

@offa
Copy link
Owner

offa commented Sep 11, 2023

Thanks for the clarification, it wasn't clear from the comment what type of exception.

I'm no MSVC dev, but following the steps described in the Readme should work there too.

There's a CI build for MSVC; it uses Conan to ship dependencies but maybe you can use it a a reference.

Can you describe the steps you use?

@fmvin
Copy link

fmvin commented Sep 11, 2023

My project is deeply tied with vcpkg. So steps are:

  1. vcpkg install boost
  2. checked cpr and libcurl are installed by vcpkg
  3. Open influxdb-cxx in CLion or Visual Studio
  4. Press build all

I tried to set flags -DBUILD_SHARED_LIBS=OFF -DCMAKE_CXX_FLAGS_INIT=-D_WIN32_WINNT=0x0A00 but it takes no effect.

@fmvin
Copy link

fmvin commented Sep 12, 2023

After several unsuccessful attempts I have built the lib and my project with vcpkg and conan as well.
The clues are these cmake's args -DBUILD_SHARED_LIBS=OFF -DCMAKE_CXX_FLAGS_INIT=-D_WIN32_WINNT=0x0A00 in right place in cmake.

@offa Thanks a lot for the reference to the solution.

@offa
Copy link
Owner

offa commented Sep 12, 2023

Great to hear! :-)

@offa
Copy link
Owner

offa commented Oct 17, 2023

@MonicaLiu0311 is this solved for you?

@MonicaLiu0311
Copy link
Author

@MonicaLiu0311 is this solved for you?

Still the same error.

@offa offa removed their assignment Feb 1, 2024
@jcar87
Copy link

jcar87 commented Feb 9, 2024

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.

@offa
Copy link
Owner

offa commented Feb 9, 2024

Thanks, this indeed could explain the issue.
Previously only non-public components were build as object libraries with all public source files in the main library.

@offa
Copy link
Owner

offa commented Apr 21, 2024

There's a test on 194-remove_internal_target branch, which builds without the internal library (let me know if you need it for 0.7.x instead). Can someone test it?

@offa offa linked a pull request Jun 5, 2024 that will close this issue
@offa
Copy link
Owner

offa commented Aug 25, 2024

ℹ️ If someone has a MSVC around, please give #245 a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants