Linker error when building with Emscripten - c++

I have an existing C++ library that I'm trying to port to Wasm using Emscripten.
The library itself builds fine:
[ 33%] Linking CXX static library libFoo.a
[ 33%] Built target Foo
However, I'm encountering a linker error when building the test suite:
[ 67%] Linking CXX executable FooTests_Run_Wasm.html
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Tests/FooTests_Run_Wasm.html] Error 1
make[1]: *** [Tests/CMakeFiles/FooTests_Run_Wasm.dir/all] Error 2
make: *** [all] Error 2
emmake: error: 'make' failed (returned 2)
Here are the linker flags I'm using:
-fexceptions
-pthread
--bind
-s ALLOW_MEMORY_GROWTH=1
-s ERROR_ON_UNDEFINED_SYMBOLS=0
-s FILESYSTEM=0
-s LLD_REPORT_UNDEFINED=1
-s PROXY_TO_PTHREAD=1
-s SAFE_HEAP=1
-s STRICT=1

Related

ld: library not found for -lstdc++fs Clang: error: linker command failed with exit code 1

I am trying to install rs_bad2image(a convert tool from bag file to images). Here is the link about this tool: https://github.com/UnaNancyOwen/rs_bag2image/blob/master/README.md
However, after the configuration and generating done successfully, I faced this error about not able to find the library -lstdc++fs.
Here is the error code:
binfeng#Bins-iMac build % cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/binfeng/Desktop/summer_project/rs_bag2image/rs_bag2image/build
binfeng#Bins-iMac build % cmake --build . --config Release
[ 33%] Linking CXX executable rs_bag2image
ld: library not found for -lstdc++fs
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [rs_bag2image] Error 1
make[1]: *** [CMakeFiles/rs_bag2image.dir/all] Error 2
make: *** [all] Error 2
If you have any idea or suggestions, please let me know. Thank in advance for any help here!

How can I solve this ? error: unable to find library -lmysqlclient

I want to compile for my program and I am stuck here , I am usig freebsd 12.1 and gcc++6.4 + gnu gmake -j20 comand
Curent path
# mysql
INCDIR += -I../../../extern/mysql
LIBDIR += -L/usr/local/lib/mysq
LIBS += -lmysqlclient -lz -pthread -lm -lssl -lcrypto
### END
Error in putty
root#vps:/usr/src/Sursa/Server/source/game/src # gmake -j20
linking ../game
ld: error: unable to find library -lmysqlclient
c++: error: linker command failed with exit code 1 (use -v to see invocation)
gmake: *** [Makefile:228: ../game] Error 1
root#vps:/usr/src/Sursa/Server/source/game/src #
root#vps:/usr/src/Sursa/Server/source/game/src #
I edited the typo and now i am geeting this
root#vps:/usr/src/Sursa/Server/source/game/src # gmake -j20
linking ../game
ld: error: /usr/local/lib/mysql/libmysqlclient.a(client.c.o) is incompatible with elf_i386_fbsd
ld: error: /usr/local/lib/mysql/libmysqlclient.a(libmysql.c.o) is incompatible with elf_i386_fbsd
ld: error: /usr/local/lib/mysql/libmysqlclient.a(crypt_genhash_impl.cc.o) is incompatible with elf_i386_fbsd
c++: error: linker command failed with exit code 1 (use -v to see invocation)
gmake: *** [Makefile:228: ../game] Error 1
root#vps:/usr/src/Sursa/Server/source/game/src #
You have a typo in LIBDIR += -L/usr/local/lib/mysq - missing l.
Make sure you have mysql57-client package installed. If not, run pkg install mysql57-client.
Also, /usr/src dir is usually used to store FreeBSD source code. It is not a best idea to use it to store your own code.

How to fix "ld: symbol(s) not found for architecture x86_64" using C++, CMake and Tensorflow?

I created a test project in C ++ using TensorFlow with CMake. But I have an error:
ld: symbol(s) not found for architecture x86_64
I think, I have an error in my CMake files. When I try compile via the terminal with gcc tensortest.cpp -ltensorflow -o tf, everything works fine.
I have two CMake files.
FindTensorFlow.cmake:
# Locates the tensorFlow library and include directories.
include(FindPackageHandleStandardArgs)
unset(TENSORFLOW_FOUND)
find_path(TensorFlow_INCLUDE_DIR
NAMES
tensorflow
HINTS
/usr/local/include/tensorflow)
find_library(TensorFlow_LIBRARY
NAMES
libtensorflow_framework.1.14.0.dylib
libtensorflow_framework.1.dylib
libtensorflow_framework.dylib
libtensorflow.1.14.0.dylib
libtensorflow.1.dylib
libtensorflow.dylib
HINTS
/usr/local/lib)
# set TensorFlow_FOUND
find_package_handle_standard_args(TensorFlow DEFAULT_MSG TensorFlow_INCLUDE_DIR TensorFlow_LIBRARY)
# set external variables for usage in CMakeLists.txt
if(TENSORFLOW_FOUND)
set(TensorFlow_LIBRARIES ${TensorFlow_LIBRARY})
set(TensorFlow_INCLUDE_DIRS ${TensorFlow_INCLUDE_DIR})
endif()
# hide locals from GUI
mark_as_advanced(TensorFlow_INCLUDE_DIR TensorFlow_LIBRARY)
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(TensorFlowTest)
set(CMAKE_CXX_STANDARD 14)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
find_package(TensorFlow REQUIRED)
include_directories(${TensorFlow_INCLUDE_DIRS} ${TensorFlow_LIBRARIES})
add_executable(TensorFlowTest main.cpp)
target_link_libraries(TensorFlowTest ${TensorFlow_INCLUDE_DIRS} ${TensorFlow_LIBRARIES})
And one main.cpp
#include <stdio.h>
#include <tensorflow/c/c_api.h>
int main() {
printf("Hello from TensorFlow C library version %s\n", TF_Version());
return 0;
}
When reload project, I have a CMake message:
-- Found TensorFlow: /usr/local/include
-- Configuring done
WARNING: Target "TensorFlowTest" requests linking to directory "/usr/local/include". Targets may link only to libraries. CMake is dropping the item.
-- Generating done
-- Build files have been written to: /Users/neikr/CLionProjects/TensorFlowTest/cmake-build-debug
And when compiling:
Scanning dependencies of target TensorFlowTest
[ 50%] Building CXX object CMakeFiles/TensorFlowTest.dir/main.cpp.o
[100%] Linking CXX executable TensorFlowTest
Undefined symbols for architecture x86_64:
"_TF_Version", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [TensorFlowTest] Error 1
make[2]: *** [CMakeFiles/TensorFlowTest.dir/all] Error 2
make[1]: *** [CMakeFiles/TensorFlowTest.dir/rule] Error 2
make: *** [TensorFlowTest] Error 2
Update
I tried make with VERBOSE=1 and I get this output:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -S/Users/neikr/CLionProjects/TensorFlowTest -B/Users/neikr/CLionProjects/TensorFlowTest --check-build-system CMakeFiles/Makefile.cmake 0
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E cmake_progress_start /Users/neikr/CLionProjects/TensorFlowTest/CMakeFiles /Users/neikr/CLionProjects/TensorFlowTest/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/TensorFlowTest.dir/build.make CMakeFiles/TensorFlowTest.dir/depend
cd /Users/neikr/CLionProjects/TensorFlowTest && /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E cmake_depends "Unix Makefiles" /Users/neikr/CLionProjects/TensorFlowTest /Users/neikr/CLionProjects/TensorFlowTest /Users/neikr/CLionProjects/TensorFlowTest /Users/neikr/CLionProjects/TensorFlowTest /Users/neikr/CLionProjects/TensorFlowTest/CMakeFiles/TensorFlowTest.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/TensorFlowTest.dir/build.make CMakeFiles/TensorFlowTest.dir/build
[ 50%] Linking CXX executable TensorFlowTest
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E cmake_link_script CMakeFiles/TensorFlowTest.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/TensorFlowTest.dir/main.cpp.o -o TensorFlowTest -Wl,-rpath,/usr/local/lib /usr/local/lib/libtensorflow_framework.1.14.0.dylib
Undefined symbols for architecture x86_64:
"_TF_Version", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [TensorFlowTest] Error 1
make[1]: *** [CMakeFiles/TensorFlowTest.dir/all] Error 2
make: *** [all] Error 2
Also, I tried adding message("TensorFlow_LIBRARIES: ${TensorFlow_LIBRARIES}") to the end of my CMake and I get this message:
TensorFlow_LIBRARIES: /usr/local/lib/libtensorflow_framework.1.14.0.dylib
Based on your print-out from the message() command, it is more clear what is going on. In your FindTensorFlow.cmake file, the find_library() call only finds one library (libtensorflow_framework.1.14.0.dylib), which is expected behavior:
Once one of the calls succeeds the result variable will be set and stored in the cache so that no call will search again.
When more than one value is given to the NAMES option this command by default will consider one name at a time and search every directory for it.
Thus, once find_library() finds the libtensorflow_framework library, the search stops. If you want to also find libtensorflow.dylib, which may help with your link error, you have to specify another find_library() call, using a different TensorFlow_ variable. So changing that section of your FindTensorFlow.cmake to something like this should help:
find_library(TensorFlow_LIBRARY
NAMES
libtensorflow.1.14.0.dylib
libtensorflow.1.dylib
libtensorflow.dylib
HINTS
/usr/local/lib)
find_library(TensorFlow_FRAMEWORK_LIBRARY
NAMES
libtensorflow_framework.1.14.0.dylib
libtensorflow_framework.1.dylib
libtensorflow_framework.dylib
HINTS
/usr/local/lib)
# set TensorFlow_FOUND
find_package_handle_standard_args(TensorFlow DEFAULT_MSG
TensorFlow_INCLUDE_DIR
TensorFlow_LIBRARY
TensorFlow_FRAMEWORK_LIBRARY
)

Cannot build opencv 2.4 on a 64 bit mac for C++ project in Xcode

After looking around a lot and trying every option I found on SO, I'm a little confused about how to get the OpenCV library for architecture x86_64 loaded on my Mac. Here's a little bit of background info:
The first folder contains the Android SDK. The second is the iPhone framework, which uses i386 and armv7 architectures.
Now, I want to create a simple "Hello World" C++ application in Xcode which needs the correct library for x86_64 architecture.
I've looked at this tutorial as well as others' posted steps as follows:
mkdir build
cd build
cmake -G "Unix Makefiles" ..
make -j8
sudo make install
With all version (except OpenCV-2.4.6.1), the process fails at "make -j8". I get the same error every time:
Linking CXX shared library ../../lib/libopencv_core.dylib
Undefined symbols for architecture x86_64:
"___sincos_stret", referenced from:
cv::RotatedRect::points(cv::Point_<float>*) const in matrix.cpp.o
cv::RotatedRect::boundingRect() const in matrix.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libopencv_core.2.4.3.dylib] Error 1
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 28%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfThreading.cpp.o
[ 28%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTileDescriptionAttribute.cpp.o
[ 28%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTiledInputFile.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTiledMisc.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTiledOutputFile.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTiledRgbaFile.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTileOffsets.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTimeCode.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTimeCodeAttribute.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfVecAttribute.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfVersion.cpp.o
[ 29%] [ 30%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfWav.cpp.o
Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfZipCompressor.cpp.o
Linking CXX static library ../lib/libIlmImf.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThread.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadMutex.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadSemaphore.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadSemaphorePosixCompat.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThread.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadMutex.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadSemaphore.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadSemaphorePosixCompat.cpp.o) has no symbols
[ 30%] Built target IlmImf
make: *** [all] Error 2
pdls-mbp:build pdl$
With OpenCV-2.4.6.1, the process fails at "sudo make install" and I get the following error:
Linking CXX shared library ../../lib/libopencv_core.dylib
Undefined symbols for architecture x86_64:
"___sincos_stret", referenced from:
cv::RotatedRect::points(cv::Point_<float>*) const in matrix.cpp.o
cv::RotatedRect::boundingRect() const in matrix.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libopencv_core.2.4.6.dylib] Error 1
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make: *** [all] Error 2
Lucys-MacBook-Pro:build pdl$
When I installed OpenCV using Homebrew, opencv was installed in use/local/opt/opencv and I can see all of the dylib files under the lib folder:
All of this completely confuses me, because I think all I need is a .a library file, no?
I have found the dylib files that were installed with HomeBrew in /usr/local/Cellar/opencv/2.4.6.1/lib but when I try to choose frameworks and libraries to add, they do not show up in the list. Instead, this is all I see:
Aldo, been following this MacPorts tutorial.
Have you considered using macports? It has opencv 2.4.8 available.
So after installing macports, all that nonsense you've been through, is reduced to:
$ sudo port selfupdate
$ sudo port install opencv
if you want a variant or two, for example OpenCL and Python support, then that would be:
$ sudo port install opencv +opencl +python27
and the binaries/libraries/whatever will be installed into /opt/local/....

Installing MathGL on OSX mavericks is causing linking errors

Hi I've been having a lot of trouble trying to build and install MathGL after upgrading to OS X Mavericks. Downloading the source and afterrunning CMake followed by make I get the following linker error:
[ 47%] Building CXX object src/CMakeFiles/mgl.dir/opengl.cpp.o
cd /Users/Maki/Desktop/mathgl-2x/src && /usr/local/Cellar/gcc48/4.8.1/bin/gcc-4.8
-Dmgl_EXPORTS - DNO_COLOR_ARRAY -DMGL_SRC -fopenmp -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -fPIC
-I/Users/Maki/Desktop/mathgl-2x/include -I/Users/Maki/Desktop/mathgl-2x/src/prc
-I/usr/local/include -o CMakeFiles/mgl.dir/opengl.cpp.o -c /Users/Maki/Desktop/mathgl-2x/src/opengl.cpp
Linking CXX shared library libmgl.dylib
after pages of output ....
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [src/libmgl.7.1.0.dylib] Error 1
make[1]: *** [src/CMakeFiles/mgl.dir/all] Error 2
make: *** [all] Error 2
Any help in getting this installed will be much appreciated.