Undefined reference when compiling library with clang - c++

I'm trying to build the libdepixelize library , but I'm getting the following error:
[100%] Linking CXX executable depixelize-kopf2011
/usr/bin/ld: /usr/local/lib/lib2geom.a(nearest-point.o): undefined reference to symbol '_ZNKSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEE3strEv##GLIBCXX_3.4.21'
//usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)
src/depixelize-kopf2011/CMakeFiles/depixelize-kopf2011.dir/build.make:95: recipe for target 'src/depixelize-kopf2011/depixelize-kopf2011' failed
make[2]: *** [src/depixelize-kopf2011/depixelize-kopf2011] Error 1
CMakeFiles/Makefile2:142: recipe for target 'src/depixelize-kopf2011/CMakeFiles/depixelize-kopf2011.dir/all' failed
make[1]: *** [src/depixelize-kopf2011/CMakeFiles/depixelize-kopf2011.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
I'm using clang with libstdc++ as compiler. GCC didn't work either.
EDIT: I used this in the CMakeLists file: set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++") and then did cmake -DCMAKE_CXX_COMPILER="clang++" .. and make to compile it. The full log is here: https://hastebin.com/axasololuc.js
I have no idea what exactly it means, or even how to fix it.

Related

Compilation Failing for xalan-c in Ubuntu

I am trying to build xalan-c (version 1.12) with icu in Ubuntu but it fails.
Could anyone help me with this.
Environment : Ubuntu 20.04
Steps to reproduce :
Clone xalan-c
cmake -G "Unix Makefiles" -DCMAKE_PREFIX_PATH="path to vcpkg installed libraries" -DCMAKE_INSTALL_PREFIX=./install/Xalan-c -DCMAKE_BUILD_TYPE=Debug -Dtranscoder=icu "path to source"
make
Error
[ 95%] Linking C executable SimpleXPathCAPI
/usr/bin/ld: /home/minhaaj/app/vcpkg/installed/x64-linux/lib/libicuuc.a(rbbistbl.ao): undefined reference to symbol '_ZTVN10__cxxabiv121__vmi_class_type_infoE##CXXABI_1.3'
/usr/bin/ld: /lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [samples/CMakeFiles/SimpleXPathCAPI.dir/build.make:90: samples/SimpleXPathCAPI] Error 1
make[1]: *** [CMakeFiles/Makefile2:842: samples/CMakeFiles/SimpleXPathCAPI.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
Please note I have applied a patch for configuration error as below in src/xalanc/Utils/MsgCreator/CMakeLists.txt
target_link_libraries(MsgCreator ICU::uc ICU::i18n)
changed to
target_link_libraries(MsgCreator ICU::uc ICU::i18n ICU::data)

Building webassembly with opencv

I've been trying to build a piece of code in webassembly that would use OpenCV.
I took https://github.com/mpizenberg/emscripten-opencv to start building, this worked well, but when I try adding cv::resize to be able to resize an image, that's when I have some issues:
make[1]: Entering directory '/code/build'
make[2]: Entering directory '/code/build'
make[3]: Entering directory '/code/build'
Scanning dependencies of target hello
make[3]: Leaving directory '/code/build'
make[3]: Entering directory '/code/build'
[ 50%] Building CXX object CMakeFiles/hello.dir/source/main.cpp.o
[100%] Linking CXX executable hello.js
error: undefined symbol: _Z7cvFloorRKN2cv10softdoubleE
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
error: undefined symbol: _Z7cvRoundRKN2cv10softdoubleE
error: undefined symbol: _Z9cvRound64RKN2cv10softdoubleE
error: undefined symbol: _ZN2cv10softdoubleC1Ei
error: undefined symbol: _ZN2cv10softdoubleC1Ex
error: undefined symbol: _ZNK2cv10softdoubledvERKS0_
error: undefined symbol: _ZNK2cv10softdoublemiERKS0_
error: undefined symbol: _ZNK2cv10softdoublemlERKS0_
error: undefined symbol: _ZNK2cv10softdoubleplERKS0_
Error: Aborting compilation due to previous errors
shared:ERROR: '/emsdk_portable/node/bin/node /emsdk_portable/sdk/src/compiler.js /tmp/tmpS6bxjF.txt /emsdk_portable/sdk/src/embind/emval.js /emsdk_portable/sdk/src/embind/embind.js /emsdk_portable/sdk/src/library_pthread_stub.js' failed (1)
CMakeFiles/hello.dir/build.make:95: recipe for target 'hello.js' failed
make[3]: *** [hello.js] Error 1
make[3]: Leaving directory '/code/build'
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/hello.dir/all' failed
make[2]: *** [CMakeFiles/hello.dir/all] Error 2
make[2]: Leaving directory '/code/build'
Makefile:83: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/code/build'
Makefile:5: recipe for target 'build' failed
make: *** [build] Error 2
The command '/bin/sh -c make build' returned a non-zero code: 2
make: *** [all] Error 2
I tried wrapping up my problem here https://github.com/jdrouet/opencv-wasm, you can pull it and run make, it'll build with docker.
Do you have any idea of how I could fix my issue?
Ok, looks like I found a way to build it (still here https://github.com/jdrouet/opencv-wasm) but now, when I try to use the resize function, I end up with the following error :
Error: the string "174007712 - Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch." was thrown, throw an Error :)
So now, I don't know if I'm not using the function well... Here is the function : https://github.com/jdrouet/opencv-wasm/blob/master/source/resizer.cpp#L23
Do you have any idea of why it's not working?

undefined reference to `omp_get_wtime'

i learn c++, OpenMP. I have tried compile my program with omp_get_wtime and it doesn't work, but when i deleted this, it works. i must add something, but what and where. In openmptryflags or Cmakelists?
snap/clion/61/bin/cmake/linux/bin/cmake --build /home/bapah/CLionProjects/omp1/cmake-build-debug --target omp1 -- -j 6
[ 50%] Linking CXX executable omp1
CMakeFiles/omp1.dir/main.cpp.o: In function `main':
/home/bapah/CLionProjects/omp1/main.cpp:36: undefined reference to `omp_get_wtime'
collect2: error: ld returned 1 exit status
CMakeFiles/omp1.dir/build.make:83: recipe for target 'omp1' failed
make[3]: *** [omp1] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/omp1.dir/all' failed
make[2]: *** [CMakeFiles/omp1.dir/all] Error 2
CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/omp1.dir/rule' failed
make[1]: *** [CMakeFiles/omp1.dir/rule] Error 2
Makefile:118: recipe for target 'omp1' failed
make: *** [omp1] Error 2
Solution :
add to CMakeList.txt
SET_TARGET_PROPERTIES(omp1 PROPERTIES COMPILE_FLAGS "-fopenmp"
LINK_FLAGS "-fopenmp")
P.s. omp1 - name your project.
P.p.s. also you can write target_link_libraries(omp1 -fopenmp)

ld: library not found for -lclangRewrite

The following error occurs when I am building eos using cmake on macOS.
ld: library not found for -lclangRewrite
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [programs/abi_gen/abi_gen] Error 1
make[1]: *** [programs/abi_gen/CMakeFiles/abi_gen.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 74%] Built target eos_chain
make: *** [all] Error 2
I find some related issues, but they are seemingly all about ios and xcode and I don't know what I should do in a project like eos. How can I fix it?
I meet the same 2 errors when building from source code of EOS step by step.
Alternatively You can use another method by running the script(https://github.com/EOSIO/eos#automac):
./build.sh darwin

Building error, cmake, can not be used when making a shared object; recompile with -fPIC

When I build a project with cmake, I got following error. Though I tried to add compiling flag -fPIC by add_definition() in the CMakeLists.txt, this error persists. Can anyone help? I am a new guy to cmake. Any suggestions will be highly appreciated.
/usr/bin/ld: /act/mvapich2-1.9/gcc-4.7.2/lib/libmpich.a(mvapich_malloc.o): relocation R_X86_64_32S against `.bss' can not be used when making a shared object; recompile with -fPIC
/act/mvapich2-1.9/gcc-4.7.2/lib/libmpich.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [src/libstracker.so] Error 1
make[2]: Leaving directory `/home/xxxx/success/AutomaDeD-master'
make[1]: *** [src/CMakeFiles/stracker.dir/all] Error 2
make[1]: Leaving directory `/home/xxxx/success/AutomaDeD-master'
make: *** [all] Error 2
add_definitions is is intended to add preprocessor definitions, not a flag
-fPIC is present by default in the linker flags for a shared library build with GCC, see Modules/Compiler/GNU.cmake. You can see all flags by running make VERBOSE=1.
As for the error itself, see this answer.