Cmake error undefined symbols for x86_64

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

I am trying to compile the conv-net library in my mac osx yosemite with xcode. I even set the flags to libstdc++ still it is not linking properly.

i still get undefined symbols for architecture x86_64. any help much appreciated.

sh-3.2# ./compile.sh Building conv-net library -- The C compiler identification is AppleClang 6.0.0.6000056 -- The CXX compiler identification is AppleClang 6.0.0.6000056 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Configuring done WARNING: Target "testimg" requests linking to directory "/usr/local/Cellar/opencv/2.4.9/lib".  Targets may link only to libraries.  CMake is dropping the item. WARNING: Target "testimg" requests linking to directory "/usr/local/Cellar/opencv/2.4.9/lib".  Targets may link only to libraries.  CMake is dropping the item. WARNING: Target "testmnist" requests linking to directory "/usr/local/Cellar/opencv/2.4.9/lib".  Targets may link only to libraries.  CMake is dropping the item. WARNING: Target "testmnist" requests linking to directory "/usr/local/Cellar/opencv/2.4.9/lib".  Targets may link only to libraries.  CMake is dropping the item. -- Generating done -- Build files have been written to: /var/tmp/conv-net-0.1-prealpha_buildroot Scanning dependencies of target cvconvnet [ 11%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvsubsamplingplane.cpp.o [ 22%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvconvolutionplane.cpp.o [ 33%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvgenericplane.cpp.o [ 44%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvsourceplane.cpp.o [ 55%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvrbfplane.cpp.o [ 66%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvmaxplane.cpp.o [ 77%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvconvnetparser.cpp.o [ 88%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvfastsigmoid.cpp.o [100%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvconvnet.cpp.o /Users/prabhubalakrishnan/Desktop/conv-net/src/cvconvnet.cpp:169:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ 1 warning generated. Linking CXX static library libcvconvnet.a [100%] Built target cvconvnet Scanning dependencies of target testimg Linking CXX executable testimg 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]: *** [testimg] Error 1 make[1]: *** [CMakeFiles/testimg.dir/all] Error 2 make: *** [all] Error 2 cp: testimg: No such file or directory cp: testmnist: No such file or directory ls: illegal option -- I usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...] 

This is my make file

cmake_minimum_required(VERSION 3.0) PROJECT (CvConvolutionalNet) set (CMAKE_CXX_FLAGS " -stdlib=libstdc++") # IF() ENDIF() statements SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)  # Specify build-type as Debug if not specified already IF (NOT CMAKE_BUILD_TYPE)     SET(CMAKE_BUILD_TYPE Debug) ENDIF ()  # Produce verbose makefiles # SET(CMAKE_VERBOSE_MAKEFILE ON)  # Sources for library SET(CVCONVNET_SRCS     src/cvsubsamplingplane.cpp     src/cvconvolutionplane.cpp     src/cvgenericplane.cpp     src/cvsourceplane.cpp     src/cvrbfplane.cpp     src/cvmaxplane.cpp     src/cvconvnetparser.cpp     src/cvfastsigmoid.cpp     src/cvconvnet.cpp )  # Sources for test files SET(TESTIMG_SRCS tst/) SET(TESTMNIST_SRCS tst/)  set (CV_H /usr/local/Cellar/opencv/2.4.9/include/opencv) set (HIGHGUI_H src/include ) set (LIBCV /usr/local/Cellar/opencv/2.4.9/lib ) set (LIBHIGHGUI /usr/local/Cellar/opencv/2.4.9/lib )  # Here are common paths (in addition to default paths) SET (INCLUDE_SEARCH_PATH     /usr/local/include /usr/include /usr/include/opencv/     /usr/include/opencv/ c:/program\ files/opencv/include )  SET (LIBRARY_SEARCH_PATH     /usr/local/lib /usr/lib c:/program\ files/opencv/lib c:/windows/system32 )  # Find OpenCV and Expat FIND_PATH(CV_H NAMES cv.h PATHS ${INCLUDE_SEARCH_PATH} ) FIND_PATH(HIGHGUI_H NAMES highgui.h PATHS ${INCLUDE_SEARCH_PATH} ) FIND_PATH(EXPAT_H NAMES expat.h PATHS ${INCLUDE_SEARCH_PATH} )  FIND_LIBRARY(LIBCV NAMES cv PATHS ${LIBRARY_SEARCH_PATH} ) FIND_LIBRARY(LIBHIGHGUI NAMES highgui PATHS ${LIBRARY_SEARCH_PATH} ) FIND_LIBRARY(LIBEXPAT NAMES expat PATHS ${LIBRARY_SEARCH_PATH} )  INCLUDE_DIRECTORIES(include/ ${CV_H} ${HIGHGUI_H} ${EXPAT_H})  # Here is out library ADD_LIBRARY(cvconvnet STATIC ${CVCONVNET_SRCS})  # Here are our test programs ADD_EXECUTABLE(testimg ${TESTIMG_SRCS}) ADD_EXECUTABLE(testmnist ${TESTMNIST_SRCS})  # Compiler options are different for Release and Debug IF (CMAKE_BUILD_TYPE MATCHES Release)     # Highly optimized + cancel all assert()s     ADD_DEFINITIONS(-O3 -DNDEBUG)  ELSE ()     # Include debug info, profiling info, some text output     ADD_DEFINITIONS(-O -pg -g -DDEBUG)     # Set profiling for linker too     SET_TARGET_PROPERTIES(testmnist PROPERTIES LINK_FLAGS "-pg") ENDIF ()  # We should link our test programs to libraries TARGET_LINK_LIBRARIES(testimg cvconvnet ${LIBCV} ${LIBHIGHGUI} ${LIBEXPAT}) TARGET_LINK_LIBRARIES(testmnist cvconvnet ${LIBCV} ${LIBHIGHGUI} ${LIBEXPAT}) 

回答1:

The add_executable command takes a target name and a list of source files to be compiled. When you are creating a target for testimg you are passing it directory.

Use file(GLOB ...) command to gather all source files from directory into a list variable and pass it to add_executable call.



回答2:

I fixed it by adding -c option in the compiler flags and it worked !!!!



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!