Azure / azure-storage-cpp

Microsoft Azure Storage Client Library for C++
http://azure.github.io/azure-storage-cpp
Apache License 2.0
131 stars 147 forks source link

Unable to run my code when I compile with build.release/Binaries/libazurestorage.a #340

Open neelam256 opened 4 years ago

neelam256 commented 4 years ago

Hi, I compile my code with build.release/Binaries/libazurestorage.a and When I run that i am getting following error undefined symbol: _ZN3web4http7methods5MERGEB5cxx11E azure-storage-cpp: 7.2.0 CPPRest: 2.10.14 Distro: Ubuntu 16.04.3 LTS

Jinming-Hu commented 4 years ago

@neelam256 Can you check where the libcpprest.so is and whether it's in the shared library search path?

neelam256 commented 4 years ago

@JinmingHu-MSFT i can see libcpprest at ./usr/local/lib/libcpprest.so
fyi I build libcpprest locally and use make install.

Jinming-Hu commented 4 years ago

@neelam256 Can you try export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib?

neelam256 commented 4 years ago

@JinmingHu-MSFT i did set the path before (1) running my function same error . (2) before compiling my library too but same error

Jinming-Hu commented 4 years ago

@neelam256 hmm, looks like a tough problem, can you share your g++ version, I'm going to try it on Ubuntu 16.04. The cpprest is built as dynamic library while azure-storage-cpp is built as static, right?

neelam256 commented 4 years ago

@JinmingHu-MSFT gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9) The cpprest is built as dynamic library while azure-storage-cpp is built as static, right ? Yes But end goal is to compile my library statically.

Jinming-Hu commented 4 years ago

@neelam256 Just tried, it works for me.

I built cpprest with

cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF -DBUILD_SAMPLES=OFF

and built azure-storage-cpp with

cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF

and finally built the executable with,

g++ -std=c++11 your_source_file.cc -I azure-storage-cpp/Microsoft.WindowsAzure.Storage/includes/ azure-storage-cpp/Microsoft.WindowsAzure.Storage/build/Binaries/libazurestorage.a -pthread -lssl -lcrypto -lcpprest -lxml2 -luuid -Wl,-Bstatic -lboost_log -lboost_system -lboost_log_setup -lboost_thread -Wl,-Bdynamic

I suppose you're linking static boost libraries

neelam256 commented 4 years ago

@JinmingHu-MSFT if compile using libboost_log.a , I got an error related to -fpic , but if compile with libboost_log.so , compilation is successful but i get error when i run test function and error is undefined symbol _ZN5boost3log12v2s_mt_posix11record_view11publicdata7destroyEPKS3 by the way i installed libboost using apt-get.

Jinming-Hu commented 4 years ago

@neelam256 I also installed boost via apt-get. It's weird that I can build pass while you always encounter problems in the same environment. Did you modify any pieces of code in azure-storage-sdk?

neelam256 commented 4 years ago

@JinmingHu-MSFT I didn't modify any code in SDK but I modify CMakeLists.txt because of error libazurestorage.a(retry_policies.cpp.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC i added set(CMAKE_POSITION_INDEPENDENT_CODE ON) in section [if GNU] around line # 91

Jinming-Hu commented 4 years ago

@neelam256 Are you trying to build a dynamic library which links against libazurestorage.a?

neelam256 commented 4 years ago

@JinmingHu-MSFT yes

Jinming-Hu commented 4 years ago

@neelam256 I tried to build a dynamic library and then build an executable with this dynamic library. It works. I didn't modify the CMake file.

I built the shared library with the command below

g++ -std=c++11 -shared -fpic -o libfunc.so func.cc -I azure-storage-cpp/Microsoft.WindowsAzure.Storage/includes/

and then built the executable with this command

g++ -std=c++11 main.cc -L. -lfunc azure-storage-cpp/Microsoft.WindowsAzure.Storage/build/Binaries/libazurestorage.a -pthread -lssl -lcrypto -lcpprest -lxml2 -luuid -Wl,-Bstatic -lboost_log -lboost_system -lboost_log_setup -lboost_thread -Wl,-Bdynamic

Can you share the commands you used to build the dynamic library and executable? Or it will be better if you can give me very short source code that can reproduce this issue.

neelam256 commented 4 years ago

@JasonYang-MSFT command to build dynamic library g++ -m64 -std=c++11 -Wall -Wextra -DSUPPORT_TYPEJ -DNOCRYPTO -Wno-unused-result -Wno-write-strings -Wno-missing-field-initializers -fno-strict-aliasing -fPIC -shared -fpermissive -I common/include/azure -I common/include -o myprogram.so src/az-storage.cpp common/lze.c common/er.c azure-storage-cpp-7.2.0/Microsoft.WindowsAzure.Storage/build.release/Binaries/libazurestorage.a -Llib/ -lssl -lcrypto -lcurl -lpthread -lcpprest -Wl,-Bstatic -lboost_log -lboost_system -lboost_log_setup -lboost_thread -Wl,-Bsymbolic -lgcc

Jinming-Hu commented 4 years ago

Hi @neelam256 , I just found that static boost libraries installed by apt-get is not compiled with -fPIC, this may cause problems when linked by dynamic libraries. So please try to link dynamic boost libraries and see if this problem persists.

neelam256 commented 4 years ago

@JinmingHu-MSFT yes i can compile with dynamic boost library and compiled successfully. But When test function of my library i got an error undefined symbol _ZN5boost3log12v2s_mt_posix11record_view11publicdata7destroyEPKS3

Jinming-Hu commented 4 years ago

@neelam256 The error undefined symbol message suggests you're still trying to link against static boost libararies. The s in v2s_mt_posix means static, see it here.

Have you used BOOST_LOG_DYN_LINK macro?

neelam256 commented 4 years ago

@JinmingHu-MSFT i didn't use BOOST_LOG_DYN_LINK macro here is detail from my compilation from strace log during build open("/usr/lib/gcc/x86_64-linux-gnu/5/libboost_log.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/libboost_log.a", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_log.so", O_RDONLY) = 18 open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_log.so", O_RDONLY) = 19 open("/usr/lib/gcc/x86_64-linux-gnu/5/libboost_system.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/libboost_system.a", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_system.so", O_RDONLY) = 19 open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_system.so", O_RDONLY) = 20 open("/usr/lib/gcc/x86_64-linux-gnu/5/libboost_log_setup.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/libboost_log_setup.a", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_log_setup.so", O_RDONLY) = 20 open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_log_setup.so", O_RDONLY) = 21 open("/usr/lib/gcc/x86_64-linux-gnu/5/libboost_filesystem.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/libboost_filesystem.a", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_filesystem.so", O_RDONLY) = 21 open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_filesystem.so", O_RDONLY) = 22 open("/usr/lib/gcc/x86_64-linux-gnu/5/libboost_thread.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/libboost_thread.a", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_thread.so", O_RDONLY) = 22 open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_thread.so", O_RDONLY) = 23 open("/usr/lib/gcc/x86_64-linux-gnu/5/libxml2.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/libxml2.a", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.so", O_RDONLY) = 23 open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libxml2.so", O_RDONLY) = 24 open("/usr/lib/gcc/x86_64-linux-gnu/5/libuuid.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/libuuid.a", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libuuid.so", O_RDONLY) =


after build List Dynamic Dependencies of my so linux-vdso.so.1 => (0x00007ffeb45c3000)
libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f6c194b9000) libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f6c19074000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6c18e57000) libcpprest.so.2.10 => /usr/local/lib/libcpprest.so.2.10 (0x00007f6c18946000) libboost_system.so.1.58.0 => /usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0 (0x00007f6c18742000) libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f6c18387000) libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f6c18182000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f6c17e00000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6c17af7000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f6c178e1000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6c17517000) /lib64/ld-linux-x86-64.so.2 (0x00007f6c19ff7000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6c17313000) libicuuc.so.55 => /usr/lib/x86_64-linux-gnu/libicuuc.so.55 (0x00007f6c16f7f000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f6c16d65000) liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f6c16b43000) libicudata.so.55 => /usr/lib/x86_64-linux-gnu/libicudata.so.55 (0x00007f6c1508c000)

Jinming-Hu commented 4 years ago

@neelam256 Please define BOOST_LOG_DYN_LINK macro or BOOST_ALL_DYN_LINK. Because according to this page, it's the right way to link dynamic boost library.

neelam256 commented 4 years ago

@JinmingHu-MSFT I tried like this g++ -m64 -std=c++11 -Wall -Wextra -DBOOST_LOG_DYN_LINK -DSUPPORT_TYPEJ -DNOCRYPTO -Wno-unused-result -Wno-write-strings -Wno-missing-field-initializers -fno-strict-aliasing -fPIC -shared -fpermissive -I common/include/azure -I common/include -o myprogram.so src/az-storage.cpp common/lze.c common/er.c azure-storage-cpp-7.2.0/Microsoft.WindowsAzure.Storage/build.release/Binaries/libazurestorage.a -Llib/ -lssl -lcrypto -lcurl -lpthread -lcpprest -Wl,-Bdynamic -lboost_log -lboost_log_setup -lboost_system -lboost_thread -lxml2 -luuid -Wl,-Bsymbolic -lgcc but i got the same result.

I used BOOST_ALL_DYN_LINK too

Jinming-Hu commented 4 years ago

@neelam256 Can you give me a short code snippet that can reproduce this issue, so that I can debug it? Because without being able to reproduce it, it will be very difficult for me to figure out the problem.

neelam256 commented 4 years ago

azure_so.zip @JinmingHu-MSFT please see the sample code where i was getting an error for boost library.

Jinming-Hu commented 4 years ago

@neelam256 I'm able to reproduce your issue. I changed the code a little bit, the cmake file of cpp sdk, your Makefile, and a test .cc. It works now at my end.

attachment, link expires in 2 weeks. I cannot upload the attachment to GitHub because it's too big.

I think this issue doesn't have too much to do with our C++ SDK, it's mainly because the way you compile is incorrect.

neelam256 commented 4 years ago

@JinmingHu-MSFT thank you, it worked