Say I have libA and libB, both needs zlib 1.2.11, and both are compiled as static lib.
my understanding is that static lib just put all .o files together. as such, both libA and libB will need zutil.c.o
to resolve symbols in their .a files.
Now I am trying to build another project that relies on both libA and libB, and that should generate a .so file. so during the linkage, the linker will find both zutil.c.o
through both libA and libB, if they point to different zutil.c.o, then error of multiple defintions of zlibs functions will occur.
The reason I am asking is that, I got this kind error when trying to build a project. But the weird part is that, with the same conanfile.py, but with different building environment i got different results. I am under ubuntu 18.04, I have conan installed only for system python3. my project uses pybind11, so i have system's own python3 and python3-dev installed (e.g., in /usr/lib/x86_64-linux-gnu/libpython3.7m.so
), I also installed conda, which has its own python3 and python3-dev installed (e.g., in /home/username/anaconda3/lib/libpython3.7m.so
), I have all conan packages that are needed installed, and they are the same for all the following building process, my conan profile sets compiler version of gcc to 9, and here is what happens.
- if I build in conda's python3 env, I can conan build the project without any problem, note that my conda comes with gcc 7.3, so i have to
set(CONAN_DISABLE_CHECK_COMPILER TRUE)
to build. - If I build with conda's python3 env, and
export CXX=/usr/lib/ccache/g++
so that system's gcc is used (actually I am using ccache here), i dont need toset(CONAN_DISABLE_CHECK_COMPILER TRUE)
, then i got the following error:
/usr/bin/ld: cannot find /lib/libpthread.so.0 /usr/bin/ld: cannot find /usr/lib/libpthread_nonshared.a collect2: error: ld returned 1 exit status
- if i build in system's python3 env, and my system has gcc 9.3, i got the following error:
/home/username/.conan/data/zlib/1.2.11///package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libz.a(zutil.o): In function
zlibVersion': zutil.c:(.text+0x0): multiple definition of
zlibVersion' /home/username/.conan/data/pcl/1.11.0///package/a4ccc62deb773be50caa050a2fb7f7e769a17a54/lib/libpcl_surface.a(zutil.c.o):zutil.c:(.text+0x0): first defined here /home/username/.conan/data/zlib/1.2.11///package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libz.a(zutil.o): In functionzlibCompileFlags': zutil.c:(.text+0x10): multiple definition of
zlibCompileFlags' /home/username/.conan/data/pcl/1.11.0///package/a4ccc62deb773be50caa050a2fb7f7e769a17a54/lib/libpcl_surface.a(zutil.c.o):zutil.c:(.text+0x10): first defined here /home/username/.conan/data/zlib/1.2.11///package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libz.a(zutil.o):(.data.rel.ro.local+0x0): multiple definition of `z_errmsg' /home/username/.conan/data/pcl/1.11.0///package/a4ccc62deb773be50caa050a2fb7f7e769a17a54/lib/libpcl_surface.a(zutil.c.o):(.data.rel.ro.local+0x0): first defined here collect2: error: ld returned 1 exit status
If I don't use conan build, just use the cmake file generated by conan and build by cmake then it is all the same multiple definition error for all cases. What I am mis-unerstanding here? or did I miss anything?