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

Including cpr in CMakeLists.txt causes linker errors in another library on Windows #1152

Open
sentientbottleofwine opened this issue Dec 9, 2024 · 2 comments

Comments

@sentientbottleofwine
Copy link

sentientbottleofwine commented Dec 9, 2024

Description

I don't really know if I should report this here or in the library that gets broken but with the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.25)
set(CMAKE_CXX_STANDARD 20)
include(FetchContent)

FetchContent_Declare(cpr 
	GIT_REPOSITORY 	https://github.com/libcpr/cpr.git
	GIT_TAG 	dec9422db3af470641f8b0d90e4b451c4daebf64
)

FetchContent_Declare(keychain
	GIT_REPOSITORY 	https://github.com/hrantzsch/keychain
	GIT_TAG        	82acee89623d0d84e1575147fb83ed387646bce8 
)

FetchContent_MakeAvailable(cpr keychain)

project(foo)

add_executable(foo
	main.cpp
)

target_link_libraries(foo
        PRIVATE keychain
	PRIVATE cpr::cpr
)

And main.cpp:

#include <cpr/cpr.h>
#include <keychain/keychain.h>

int main() {
    // The code isn't that important it's just for the functions to be linked to the executable
    cpr::Response r = cpr::Get( cpr::Url{"https://example.com"} );
    keychain::Error err;
    keychain::setPassword("dasd", "asdasda", "dasdasd", "asd", err);
}

The build breaks and throws out linker errors that reference keychain. This only happens when I include cpr. Other libs work fine. There is one weird thing, when I switch the order in FetchContent_MakeAvailable():

FetchContent_MakeAvailable(keychain cpr)

The build works.
Logs of failed build:
https://pastebin.com/iKSpKjqq
https://pastebin.com/L75nGhHx

Logs of successful build(with switched order):
https://pastebin.com/28f7taQP
https://pastebin.com/mQfsw97a
On linux everything works no matter the order. I'm using clang + msvc(as stdlib) + ninja.

Example/How to Reproduce

  • On a windows setup with clang + msvc + ninja(I used this guide , it's just downloading clang and ninja).
  • Create files CMakeLists.txt and main.cpp with the contents specified above.
  • Run
cmake . -G Ninja -B build
cmake --build build/
  • Observe linker error occurring based on CMakeLists.txt

Possible Fix

No response

Where did you get it from?

GitHub (branch e.g. master)

Additional Context/Your Environment

  • OS: Windows
  • Version: 11
@COM8
Copy link
Member

COM8 commented Dec 9, 2024

@sentientbottleofwine thanks for reporting and this well written issue!

I had a quick look at it and it looks like it's a Windows only issue. I tested it on Fedora (Silverblue) 41 and there both orders work.

I suspect there are actually missing includes in the keychain source code and it most likely is not directly related to cpr.

@COM8 COM8 added the Build 👷 label Dec 9, 2024
@sentientbottleofwine
Copy link
Author

@COM8 I'm not sure if I understand you correctly but building keychain alone works fine(altough I had to remove the build directory and rerun cmake . -G Ninja -B build, probably because of some caching issues). I don't know how that would be caused by missing includes if one order works fine, could you elaborate?

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

No branches or pull requests

2 participants