redox icon indicating copy to clipboard operation
redox copied to clipboard

Has anyone have the below linking issue?

Open MadMichael888 opened this issue 10 years ago • 9 comments

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 avatar Oct 12 '15 22:10 MadMichael888

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;

}

MadMichael888 avatar Oct 12 '15 22:10 MadMichael888

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

hmartiro avatar Oct 18 '15 21:10 hmartiro

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 [email protected] wrote:

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

— Reply to this email directly or view it on GitHub https://github.com/hmartiro/redox/issues/31#issuecomment-149047452.

MadMichael888 avatar Oct 22 '15 01:10 MadMichael888

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

hmartiro avatar Nov 15 '15 00:11 hmartiro

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

mjohnson138 avatar Mar 18 '17 15:03 mjohnson138

@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.

Yaoshicn avatar Jul 12 '17 18:07 Yaoshicn

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

mjohnson138 avatar Jul 14 '17 03:07 mjohnson138

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 ?

bveldhoen avatar Jul 14 '17 05:07 bveldhoen

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.

mjohnson138 avatar Apr 15 '20 21:04 mjohnson138