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

Has anyone have the below linking issue? #31

Open
MadMichael888 opened this issue Oct 12, 2015 · 9 comments
Open

Has anyone have the below linking issue? #31

MadMichael888 opened this issue Oct 12, 2015 · 9 comments

Comments

@MadMichael888
Copy link

Hi,

I was able to compile my application cpp but when I tried to link, I have the below error:

/tmp/ccIM35WN.o: In function main': MyApp.cpp:(.text+0x47f): undefined reference toredox::Redox::connect(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int, std::function<void (int)>)'
collect2: error: ld returned 1 exit status

Thanks,
Mike

@MadMichael888
Copy link
Author

I have attached my code below, it's pretty simple. I also tried to remove the libredox.so from /usr/local/lib64/ and see if it was a lib issue, but when I do that I got this error (which proves that the linker is able to find the lib):

/usr/bin/ld: cannot find -lredox
collect2: error: ld returned 1 exit status

#include
#include <redox.hpp>

using namespace std;
using namespace redox;

int main(int argc, char* argv[]) {
Redox rdx;
if(!rdx.connect("localhost", 6379)) return 1;
cout << "Redis connected." << endl;

rdx.disconnect();
return 0;

}

@hmartiro
Copy link
Owner

Hi Michael, did you try providing the directory of libredox.so with -L?

@MadMichael888
Copy link
Author

Yes. I did. I even tried to remove the .so and it gave me a different
error. So it appears to be able to find the lib.

On Mon, Oct 19, 2015 at 5:07 AM, Hayk Martirosyan notifications@github.com
wrote:

Hi Michael, did you try providing the directory of libredox.so with -L?


Reply to this email directly or view it on GitHub
#31 (comment).

@hmartiro
Copy link
Owner

Can you post your compile command? Did you compile w/ C++11?

@mjohnson138
Copy link

I am actually hitting this issue currently while trying to build the Hello World example. Below is my compile command:

[mjohnson138@localhost development]$ g++ hello.cpp -o hello -std=c++11 -Xlinker --verbose -I/usr/local/include/ -lredox -lev -lhiredis | grep redox attempt to open /opt/gcc/gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/libredox.so failed attempt to open /opt/gcc/gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/libredox.a failed attempt to open /opt/gcc/gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../lib64/libredox.so failed attempt to open /opt/gcc/gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../lib64/libredox.a failed attempt to open /lib/../lib64/libredox.so failed attempt to open /lib/../lib64/libredox.a failed attempt to open /usr/lib/../lib64/libredox.so failed attempt to open /usr/lib/../lib64/libredox.a failed attempt to open /opt/gcc/gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../libredox.so failed attempt to open /opt/gcc/gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../libredox.a failed attempt to open /usr/x86_64-redhat-linux/lib64/libredox.so failed attempt to open /usr/x86_64-redhat-linux/lib64/libredox.a failed attempt to open /usr/local/lib64/libredox.so succeeded -lredox (/usr/local/lib64/libredox.so) libpthread.so.0 needed by /usr/local/lib64/libredox.so /tmp/ccjzvbw5.o: In function main':
hello.cpp:(.text+0x3fd): undefined reference to redox::Redox::connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, std::function<void (int)>)' hello.cpp:(.text+0x4ab): undefined reference to redox::Redox::set(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'
hello.cpp:(.text+0x51f): undefined reference to redox::Redox::get(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' collect2: error: ld returned 1 exit status

@Yaoshicn
Copy link

Yaoshicn commented Jul 12, 2017

@mjohnson138 I met same problem with g++ 5. Have you come up any idea on this issue? Thanks in advance.

BTW, if I switch to g++ 4.9.2, there is no problem any more. Since I have to use std::put_time(), g++ 5 is necessary.

@mjohnson138
Copy link

@Yaoshicn Unfortunately I was not able to get past the issue. I chose to no longer use Redis for my software project.

@bveldhoen
Copy link
Contributor

No need to dump redox (or redis) over a linker error. This may be related to the change of default ABI by gcc, see here: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html.
Some questions:

  • Which os and version and gcc version are you using?
  • Did you recompile redox, or use a prebuilt binary?
  • Can you retry by specifying -D_GLIBCXX_USE_CXX11_ABI=0 ?

@mjohnson138
Copy link

Many apologies for the late response on this, but I was finally able to return to this library and solve the original issue. In CMake, the set(CMAKE_CXX_COMPILER, ...) option was being ignored (https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-do-i-use-a-different-compiler) and so the redox library was being built with a pre-c++11 version of GCC while the project that was linking against redox was built using a new compiler. Good call on the dual_abi as that break was causing the issue. Ultimately, I set CC and CXX on the cmake line in the provided make.sh script.

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

No branches or pull requests

5 participants