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

[libtorrent] Fix linkage issues for dynamic builds #7345

Merged
merged 4 commits into from
Jan 16, 2020

Conversation

ras0219-msft
Copy link
Contributor

Fixes arvidn/libtorrent#3878.

Due to supporting consuming buildsystems other than CMake, we patch the installed headers to set required linkage macros. This fix causes us to patch in the correct usage macro, instead of the internal build macro.

Without this fix, the example on https://www.libtorrent.org/examples.html fails to link in x86-windows. With this fix, it successfully links.

@ras0219-msft ras0219-msft self-assigned this Jul 20, 2019
@ras0219-msft ras0219-msft added the info:internal This PR or Issue was filed by the vcpkg team. label Jul 20, 2019
@myd7349
Copy link
Contributor

myd7349 commented Jul 20, 2019

CI failure on Linux: #7344

@pmahend1
Copy link

@ras0219-msft do I have to make these changes in my local C:\workspace\vcpkg\ports\libtorrent and then do I have to rerun bootstrap-vcpkg.bat?

@pmahend1
Copy link

pmahend1 commented Jul 22, 2019

So I updated the port files and then uninstalled all the libtorrent triplet packages and installed again;

To be double sure ran .\vcpkg.exe build libtorrent again but still I see linking issues

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK1120	2 unresolved externals	MyprojectTorrent	C:\workspace\Myproject\x64\Debug\MyprojectTorrent.exe	1	
Error	LNK2019	unresolved external symbol "public: __cdecl libtorrent::internal_file_entry::~internal_file_entry(void)" (??1internal_file_entry@libtorrent@@QEAA@XZ) referenced in function "public: void * __cdecl libtorrent::internal_file_entry::`scalar deleting destructor'(unsigned int)" (??_Ginternal_file_entry@libtorrent@@QEAAPEAXI@Z)	MyprojectTorrent	C:\workspace\Myproject\MyprojectTorrent\Myproject_torrent_client.obj	1	
Error	LNK2001	unresolved external symbol "class libtorrent::from_span_t libtorrent::from_span" (?from_span@libtorrent@@3Vfrom_span_t@1@A)	MyprojectTorrent	C:\workspace\Myproject\MyprojectTorrent\Myproject_torrent_client.obj	1	
Error	LNK2001	unresolved external symbol "public: __cdecl libtorrent::internal_file_entry::~internal_file_entry(void)" (??1internal_file_entry@libtorrent@@QEAA@XZ)	MyprojectTorrent	C:\workspace\Myproject\MyprojectTorrent\Runner.obj	1	
Error	LNK2001	unresolved external symbol "class libtorrent::from_span_t libtorrent::from_span" (?from_span@libtorrent@@3Vfrom_span_t@1@A)	MyprojectTorrent	C:\workspace\Myproject\MyprojectTorrent\Runner.obj	1	

@pmahend1
Copy link

pmahend1 commented Jul 23, 2019

Somehow I got rid off all the linking issues. Not sure which one worked.

  • I edited port file as mentioned by @ras0219-msft
  • rebuilt libtorrent by vcpkg build libtorrent:<triplet> and then started fresh project.
  • Only copied torrent client from example.
  • added preprocessor directive TORRENT_NO_DEPRECATE and TORRENT_DEBUG(not sure if this is important)
  • compiled client project
  • it started asking for other dependent dlls like torrent-rasterbar, boost, openssl , added them to runtime directory.
  • I dont see linking issue.

On other hand if I run client.exe base_text.txt I get Exception thrown at 0x00007FF93B2D1314 (vcruntime140d.dll) in client.exe: 0xC0000005: Access violation writing location 0x00007FF7534E7400. I dont think this issue is related but I will check further.

This is in 64 bit debug.

Note : for 32 bit I get error

application was unable to start correctly 0xNNNNN

@ras0219-msft
Copy link
Contributor Author

The following worked for me (checked out to this PR branch):

>git clone https://github.com/arvidn/libtorrent -b libtorrent-1_2_1

then rewrite the examples cmake slightly:

# examples/CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
project(libtorrent-examples)

set(single_file_examples
    simple_client
    custom_storage
    stats_counters
    dump_torrent
    make_torrent
    connection_tester
    upnp_test)

find_package(LibtorrentRasterbar CONFIG REQUIRED)

foreach(example ${single_file_examples})
    add_executable(${example} "${example}.cpp")
    target_link_libraries(${example} PRIVATE LibtorrentRasterbar::torrent-rasterbar)
endforeach(example)

add_executable(client_test
    client_test.cpp
    print.cpp
    torrent_view.cpp
    session_view.cpp)
target_link_libraries(client_test PRIVATE LibtorrentRasterbar::torrent-rasterbar)

Then a simple:

>vcpkg install libtorrent:x86-windows
>cmake ..\.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=D:\src\vcpkg\scripts\buildsystems\vcpkg.cmake -G Ninja
>ninja
>.\client_test.exe

worked. I'll note that there were some warnings during the build process about dll-linkage.

Also note that vcpkg build is not the same as vcpkg install, and I'd recommend preferring remove+install over build.

@JackBoosY JackBoosY added the info:reviewed Pull Request changes follow basic guidelines label Jan 14, 2020
@vicroms vicroms merged commit 562515f into microsoft:master Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info:internal This PR or Issue was filed by the vcpkg team. info:reviewed Pull Request changes follow basic guidelines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

link errors in vcpkg
6 participants