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

Link error when building example with Conan #125

Closed
Pwera opened this issue Aug 14, 2016 · 10 comments
Closed

Link error when building example with Conan #125

Pwera opened this issue Aug 14, 2016 · 10 comments

Comments

@Pwera
Copy link

Pwera commented Aug 14, 2016

After successfully install cpr with Conan, i tried to compil an example.
I am using gcc 5.3.

project(Ques)
cmake_minimum_required(VERSION 3.5.2)
SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -std=c++14)

include(conanbuildinfo.cmake)
conan_basic_setup()
add_executable(Ques main.cpp)

message(STATUS ${CONAN_LIBS})
target_link_libraries(Ques ${CONAN_LIBS})

main.cpp content:

#include <cpr/cpr.h>
#include <iostream>
#include <string>
int main(int argc, char** argv)
{
    auto r = cpr::Get(cpr::Url{"https://api.github.com/repos/whoshuu/cpr/contributors"},
                      cpr::Authentication{"user", "pass"},
                      cpr::Parameters{{"anon", "true"}, {"key", "value"}});
    r.status_code;                  // 200
    r.header["content-type"];      // application/json; charset=utf-8
    r.text;   
    return 0;
}

TerminalOutput :

[ 50%] Building CXX object CMakeFiles/Ques.dir/main.cpp.o
[100%] Linking CXX executable bin/Ques
CMakeFiles/Ques.dir/main.cpp.o: In function `std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, cpr::CaseInsensitiveCompare, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::operator[](std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)':
main.cpp:(.text._ZNSt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_N3cpr22CaseInsensitiveCompareESaISt4pairIKS5_S5_EEEixEOS5_[_ZNSt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_N3cpr22CaseInsensitiveCompareESaISt4pairIKS5_S5_EEEixEOS5_]+0x90): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
CMakeFiles/Ques.dir/main.cpp.o: In function `void cpr::priv::set_option<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(cpr::Session&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)':
main.cpp:(.text._ZN3cpr4priv10set_optionINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEvRNS_7SessionEOT_[_ZN3cpr4priv10set_optionINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEvRNS_7SessionEOT_]+0x2a): undefined reference to `cpr::Session::SetOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles/Ques.dir/main.cpp.o: In function `std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, cpr::CaseInsensitiveCompare, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_M_get_insert_hint_unique_pos(std::_Rb_tree_const_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
main.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS8_ERS7_[_ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS8_ERS7_]+0xa1): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
main.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS8_ERS7_[_ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS8_ERS7_]+0x147): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
main.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS8_ERS7_[_ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS8_ERS7_]+0x202): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
main.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS8_ERS7_[_ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS8_ERS7_]+0x2dd): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
main.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS8_ERS7_[_ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS8_ERS7_]+0x386): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
CMakeFiles/Ques.dir/main.cpp.o:main.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE14_M_insert_nodeEPSt18_Rb_tree_node_baseSG_PSt13_Rb_tree_nodeIS8_E[_ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE14_M_insert_nodeEPSt18_Rb_tree_node_baseSG_PSt13_Rb_tree_nodeIS8_E]+0x5e): more undefined references to `cpr::CaseInsensitiveCompare::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const' follow
collect2: error: ld returned 1 exit status

Where i did mistake?

@DEGoodmanWilson
Copy link
Contributor

What does your conanfile look like?

@Pwera
Copy link
Author

Pwera commented Aug 16, 2016

conanfile content

[requires]
cpr/1.2.0@DEGoodmanWilson/testing

[generators]
cmake

conaninfo content:

[settings]
    arch=x86_64
    build_type=Release
    compiler=gcc
    compiler.libcxx=libstdc++
    compiler.version=5.3
    os=Linux

[requires]
    cpr/1.Y.Z

[options]


[full_settings]
    arch=x86_64
    build_type=Release
    compiler=gcc
    compiler.libcxx=libstdc++
    compiler.version=5.3
    os=Linux

[full_requires]
    OpenSSL/1.0.2g@lasote/stable:c9485444fc54028aa59ea9eb50adf168f08452e3
    cpr/1.2.0@DEGoodmanWilson/testing:cf6314884dde623a25b4a301b0753d616b08ceb4
    electric-fence/2.2.0@lasote/stable:52bcde7d26fabb9754f2f3b850001579b1098686
    libcurl/7.49.1@lasote/stable:08913c0fb0493a775104b4be5020b20022e6fc21
    zlib/1.2.8@lasote/stable:52bcde7d26fabb9754f2f3b850001579b1098686

[full_options]
    OpenSSL:386=False
    OpenSSL:no_asm=False
    OpenSSL:no_bf=False
    OpenSSL:no_cast=False
    OpenSSL:no_des=False
    OpenSSL:no_dh=False
    OpenSSL:no_dsa=False
    OpenSSL:no_electric_fence=False
    OpenSSL:no_hmac=False
    OpenSSL:no_md2=False
    OpenSSL:no_md5=False
    OpenSSL:no_mdc2=False
    OpenSSL:no_rc2=False
    OpenSSL:no_rc4=False
    OpenSSL:no_rc5=False
    OpenSSL:no_rsa=False
    OpenSSL:no_sha=False
    OpenSSL:no_sse2=False
    OpenSSL:no_threads=False
    OpenSSL:no_zlib=False
    OpenSSL:shared=False
    OpenSSL:zlib_dynamic=False
    cpr:insecure_curl=False
    cpr:use_ssl=True
    cpr:use_system_curl=False
    electric-fence:shared=False
    libcurl:custom_cacert=False
    libcurl:disable_threads=False
    libcurl:shared=False
    libcurl:with_ldap=False
    libcurl:with_libidn=False
    libcurl:with_libmetalink=False
    libcurl:with_librtmp=False
    libcurl:with_libssh2=False
    libcurl:with_openssl=True
    zlib:shared=False

[scope]
    dev=True

@DEGoodmanWilson
Copy link
Contributor

OK, I've been able to replicate. Digging in now!

@DEGoodmanWilson
Copy link
Contributor

And, compiling without Conan doesn't lead to this error. It looks like Conan is somehow not successfully linking in CPR under gcc 5.3. FWIW, your example works just fine in 4.9. I'm going to page @lasote on this one…

@DEGoodmanWilson
Copy link
Contributor

There are some very interesting differences in the generated conanbuildinfo.cmake files that seem worth mentioning. Here is the output of comparing the file generated with GCC5.3 and GCC4.9 (with the irrelevant difference filtered out).

diff conanbuildinfo.cmake.gcc53 conanbuildinfo.cmake.gcc49
55a56,57
> set(CONAN_PACKAGE_NAME None)
> set(CONAN_PACKAGE_VERSION None)
82a85,88
>     conan_set_find_paths()
> endmacro()
> 
> macro(conan_set_find_paths)
84a91,93
> 
>     # Make find_package() to work
>     set(CMAKE_PREFIX_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_PREFIX_PATH})
88c97,101
<     include_directories(SYSTEM ${CONAN_INCLUDE_DIRS})
---
>     if(CONAN_SYSTEM_INCLUDES)
>         include_directories(SYSTEM ${CONAN_INCLUDE_DIRS})
>     else()
>         include_directories(${CONAN_INCLUDE_DIRS})
>     endif()

@DEGoodmanWilson
Copy link
Contributor

Although those differences don't appear to actually be relevant. I merged them into the gcc4.9 conanbuildinfo.cmake, and got the same linker errors :(

@DEGoodmanWilson
Copy link
Contributor

DEGoodmanWilson commented Aug 18, 2016

@Pwera I have it figured out. The problem is that somewhere along the line, I'm not entirely sure where, something is getting compiled with an ABI-incompatible libstdc++. This should do the trick:

conan install -s compiler=gcc -s compiler.libcxx=libstdc++11 --build=missing

This will ensure that all dependencies, are compiled with the correct libstdc++ ABI

(Alternately, you can update .conan/conan.conf to reflect that setting across the board.)

@lasote
Copy link

lasote commented Aug 19, 2016

HI! sorry for the delay. I can see that you have already solve the issue. 👍 If the setting libcxx is not set to libstcd++11 it won't link with C++11 capabilities, so this setting is needed.

@hbobenicio
Copy link

This issue is already solved, right?
Think someone can close this, I guess...
@tstack ?

@COM8
Copy link
Member

COM8 commented Apr 28, 2020

This issue has been solved and the conan package is ready to be used without any problems.
I'm closing this issue.
Feel free to reopen it or open a new issue if you experience any problems with that.

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

5 participants