Subtitle: Undefined symbols for architecture x86_64: Building OpenCV and dlib with SCons on Mac OSX El Captain x86_64
I've been trying to make my app build in cross platform.
I have an SCons script that currently builds fine on windows, but it fails to build so in Mac.
I believe it is caused by some clashes with newer versions of XCode, because some of the previous versions of my code and scons worked nicely (before being refactored).
The following is the error message, and I believe it is quite common, but I seem to fail to find a way to remedy it.
In OpenCV2-highgui, cap_avfoundation.mm
Undefined symbols for architecture x86_64:
"_AVCaptureSessionPresetMedium", referenced from:
CvCaptureCAM::startCaptureDevice(int) in libOpencvHighgui.a(cap_avfoundation.o)
"_AVFileTypeAppleM4V", referenced from:
CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in libOpencvHighgui.a(cap_avfoundation.o)
"_AVFileTypeMPEG4", referenced from:
CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in libOpencvHighgui.a(cap_avfoundation.o)
"_AVFileTypeQuickTimeMovie", referenced from:
CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in libOpencvHighgui.a(cap_avfoundation.o)
"_AVMediaTypeVideo", referenced from:
CvCaptureCAM::startCaptureDevice(int) in libOpencvHighgui.a(cap_avfoundation.o)
CvCaptureFile::CvCaptureFile(char const*) in libOpencvHighgui.a(cap_avfoundation.o)
CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in libOpencvHighgui.a(cap_avfoundation.o)
...
...
...
In OpenCV2-highgui, window_cocoa.mm
"_OBJC_CLASS_$_NSSlider", referenced from:
objc-class-ref in libOpencvHighgui.a(window_cocoa.o)
"_OBJC_CLASS_$_NSString", referenced from:
objc-class-ref in libOpencvHighgui.a(window_cocoa.o)
objc-class-ref in libOpencvHighgui.a(cap_avfoundation.o)
"_OBJC_CLASS_$_NSTextField", referenced from:
objc-class-ref in libOpencvHighgui.a(window_cocoa.o)
"_OBJC_CLASS_$_NSThread", referenced from:
objc-class-ref in libOpencvHighgui.a(window_cocoa.o)
"_OBJC_CLASS_$_NSURL", referenced from:
...
...
...
In addition to building OpenCV, same error occurred in dlib_18_14, source.cpp
"_XAllocColor", referenced from:
void nativefont::font_renderer::font_renderer::vals_internal::create<unsigned int>(unsigned int*, int, bool, bool, bool, nativefont::font_renderer::font_renderer::rgb_type, nativefont::font_renderer::font_renderer::rgb_type) in libThirdPartyDlib_18_14.a(source.o)
"_XAllocSizeHints", referenced from:
dlib::base_window::set_size(int, int) in libThirdPartyDlib_18_14.a(source.o)
dlib::base_window::base_window(bool, bool) in libThirdPartyDlib_18_14.a(source.o)
dlib::gui_core_kernel_2_globals::event_handler_thread::event_handler() in libThirdPartyDlib_18_14.a(source.o)
"_XChangeProperty", referenced from:
dlib::gui_core_kernel_2_globals::event_handler_thread::event_handler() in libThirdPartyDlib_18_14.a(source.o)
"_XCheckIfEvent", referenced from:
dlib::gui_core_kernel_2_globals::event_handler_thread::event_handler() in libThirdPartyDlib_18_14.a(source.o)
"_XClearArea", referenced from:
dlib::base_window::invalidate_rectangle(dlib::rectangle const&) in libThirdPartyDlib_18_14.a(source.o)
"_XCloseDisplay", referenced from:
nativefont::font_renderer::font_renderer::vals_internal::~vals_internal() in libThirdPartyDlib_18_14.a(source.o)
dlib::gui_core_kernel_2_globals::event_handler_thread::~event_handler_thread() in libThirdPartyDlib_18_14.a(source.o)
"_XCloseIM", referenced from:
dlib::gui_core_kernel_2_globals::event_handler_thread::~event_handler_thread() in libThirdPartyDlib_18_14.a(source.o)
"_XConvertSelection", referenced from:
dlib::get_from_clipboard(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&) in libThirdPartyDlib_18_14.a(source.o)
"_XCreateFontSet", referenced from:
dlib::base_window::base_window(bool, bool) in libThirdPartyDlib_18_14.a(source.o)
void nativefont::font_renderer::font_renderer::vals_internal::create<unsigned int>(unsigned int*, int, bool, bool, bool, nativefont::font_renderer::font_renderer::rgb_type, nativefont::font_renderer::font_renderer::rgb_type) in libThirdPartyDlib_18_14.a(source.o)
...
...
...
And the error is summed up as the following:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [out/darwin/x86_64/release/1.0.0/bin/libAPI3dfi_api_v1.dylib] Error 1
scons: building terminated because of errors.
I cannot expose the entire source code nor the scons build scripts here, so please mind that.
This is the sample snippet of how my scons script looks like to build a shared library (building static libraries are having no problems, just the shared libs):
Import('env')
# Add third party libraries
lib_env = env.Clone()
module_lib_env = lib_env.Clone()
target_os = env.get('TARGET_OS')
target_arch = env.get('TARGET_ARCH')
######################################################################
# Runtime Dependencies
######################################################################
pthread_path = env.get('PTHREAD_PATH') + '/lib'
intraface_path = env.get('INTRAFACE_PATH') + '/lib'
######################################################################
# General flags
######################################################################
module_lib_env.AppendUnique(CPPPATH = ['inc', 'src'])
######################################################################
# Libraries
######################################################################
module_lib_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')+'/bin',env.get('BUILD_DIR')+'/lib', pthread_path, intraface_path])
if target_os == 'windows':
module_lib_env.AppendUnique(LIBS = [
'libOpencvCore',
'libOpencvHighgui',
'libOpencvImgproc',
'libOpencvObjdetect',
'libOpencvFlann',
'libOpencvFeature2d',
'libOpencvVideo',
'libOpencvCalib3d',
'libOpencvMl',
'libFreeimage',
'libFreeimageOpenEXR',
'libFreeimageLibTIFF',
#'libFreeimageLibRawLite',
'libFreeimageLibPNG',
'libFreeimageLibOpenJPEG',
'libFreeimageLibJPEG',
'libFreeimageLibMNG',
'libFreeimageZLib',
'libThirdPartyDlib_18_14',
'pthread',
'IntraFaceDLL'])
else:
module_lib_env.AppendUnique(LIBS = [
'libOpencvCore',
'libOpencvHighgui',
'libOpencvImgproc',
'libOpencvObjdetect',
'libOpencvFlann',
'libOpencvFeature2d',
'libOpencvVideo',
'libOpencvCalib3d',
'libOpencvMl',
'libFreeimage',
'libFreeimageOpenEXR',
'libFreeimageLibTIFF',
#'libFreeimageLibRawLite',
'libFreeimageLibPNG',
'libFreeimageLibOpenJPEG',
'libFreeimageLibJPEG',
'libFreeimageLibMNG',
'libFreeimageZLib',
'libThirdPartyDlib_18_14',
'pthread'
# ,'IntraFaceDLL'
])
######################################################################
# Preprocessor flags
######################################################################
if not target_os == 'windows':
#allow error to be concidered as warning
module_lib_env.AppendUnique(CCFLAGS = ['-fpermissive'])
#disable warning
module_lib_env.AppendUnique(CCFLAGS = ['-Wno-sign-compare'])
module_lib_env.AppendUnique(CCFLAGS = ['-Wno-write-strings'])
module_lib_env.AppendUnique(CCFLAGS = ['-Wno-unused-variable'])
if target_os in ['darwin', 'ios']:
module_lib_env.AppendUnique(CPPDEFINES = ['_LIBCPP_HAS_NO_VARIADICS'])
######################################################################
# Source files and Targets
######################################################################
lib_src = env.Glob('src/*.cpp')
######################################################################
# Targets
######################################################################
module_lib_env.InstallTargetShared('libOpenCV', lib_src )
Here is the Full error log.
Here is how InstallTargetShared looks like:
def __install_shared(ienv, name, srcs):
ienv.SharedLibrary(target = os.path.join(env.get('BUILD_DIR') +'/bin/', name), source = srcs)
env.AppendUnique(TS = [name])
env.AddMethod(__install_shared, 'InstallTargetShared')
Any help or advices of what to do in this matter will be much appreciated!!
Looking at your full build log, I think you need to link against several OSX frameworks to resolve your issues. I don't see any in your linking command line:
g++ -o out/darwin/x86_64/release/1.0.0/bin/libAPI3dfi_api_v1.dylib -ldl -lpthread -mmacosx-version-min=10.11 -DWITH_OPENEXR=OFF -dynamiclib out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Api.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_App_Manager.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_App_Params.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_App_Retry.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Device_Heartbeat.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Device_Init.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Frame_Stats.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Manager.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Session_Assign.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Session_End.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Session_Start.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/SHA1Hash.os -L/usr/local/lib -L/opt/local/lib -Ldeps/darwin/lib/x86_64 -Lout/darwin/x86_64/release/1.0.0 -L. -Lout/darwin/x86_64/release/1.0.0/bin -Lbin -Lout/darwin/x86_64/release/1.0.0/lib -Llib -L/Users/tllewellynn/Desktop/dev/build_scons/runtime/darwin/xcode/x86_64/pthread/lib -L/Users/tllewellynn/Desktop/dev/build_scons/runtime/darwin/xcode/x86_64/intraface/lib -lSDK3dfi_detect -lSDK3dfi_algo -lSDK3dfi_au -lSDK3dfi_align -lSDK3dfi_proc -lSDK3dfi_cluster -lSDK3dfi_attr -lSDK3dfi_type -lOpencvCore -lOpencvHighgui -lOpencvImgproc -lOpencvObjdetect -lOpencvFlann -lOpencvFeature2d -lOpencvVideo -lOpencvCalib3d -lOpencvMl -lFreeimage -lFreeimageOpenEXR -lFreeimageLibTIFF -lFreeimageLibPNG -lFreeimageLibOpenJPEG -lFreeimageLibJPEG -lFreeimageLibMNG -lFreeimageZLib -lFrameworkNvaam_base -lFrameworkNvaam_filter -lFrameworkNvaam -lFrameworkProtobuf -lFrameworkLibbff -lFrameworkNvclassifier -lFrameworkNvexpression -lFrameworkTrimesh2 -lFrameworkPolyfit -lFrameworkGClasses -lFrameworkFlandmark -lFrameworkAlglib -lNetMsgpack -lNetJsoncpp -lNetTinyxml2 -lNetTinyxmlparam -lCnnEblearnTools -lCnnEblearnIdx -lCnnEblearn -lThirdPartyDlib_18_14 -lSystemTinycthread -lSystemTinythread -lSystemGlobal -lSystemDebug -lpthread -lTbb -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/
Have you asked on any openCV forums or IRC channels?
Looks like you're missing several key frameworks from your link line.
Related
I'm trying to parallelize my code via TBB library, using the tool tbb::parallel_for. I use a Mac OS computer and I downloaded and installed Tbb with Homebrew.
The Tbb is in Macintosh HD ▸ opt ▸ intel ▸ compilers_and_libraries_2020.1.216 ▸ mac ▸ tbb ▸ include.
When I try to compile the following error appears:
"tbb::interface5::internal::task_base::destroy(tbb::task&)", referenced from:
tbb::flow::interface10::graph::~graph() in interface_stokes.cpp.o
"tbb::interface7::internal::task_arena_base::internal_terminate()", referenced from:
tbb::interface7::task_arena::terminate() in interface_stokes.cpp.o
"tbb::interface7::internal::task_arena_base::internal_initialize()", referenced from:
tbb::interface7::task_arena::initialize() in interface_stokes.cpp.o
"tbb::task_group_context::init()", referenced from:
tbb::task_group_context::task_group_context(tbb::internal::string_index) in interface_stokes.cpp.o
"tbb::task_group_context::reset()", referenced from:
tbb::flow::interface10::graph::wait_for_all() in interface_stokes.cpp.o
"tbb::task_group_context::~task_group_context()", referenced from:
tbb::flow::interface10::graph::~graph() in interface_stokes.cpp.o
tbb::interface9::internal::start_for<tbb::blocked_range<unsigned long>, tbb::internal::parallel_for_body<main::$_0, unsigned long>, tbb::auto_partitioner const>::run(tbb::blocked_range<unsigned long> const&, tbb::internal::parallel_for_body<main::$_0, unsigned long> const&, tbb::auto_partitioner const&) in interface_stokes.cpp.o
"tbb::task::note_affinity(unsigned short)", referenced from:
vtable for tbb::interface9::internal::flag_task in interface_stokes.cpp.o
"tbb::internal::throw_exception_v4(tbb::internal::exception_id)", referenced from:
tbb::internal::throw_exception(tbb::internal::exception_id) in interface_stokes.cpp.o
"tbb::internal::get_initial_auto_partitioner_divisor()", referenced from:
tbb::interface9::internal::adaptive_mode<tbb::interface9::internal::auto_partition_type>::adaptive_mode() in interface_stokes.cpp.o
"tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const", referenced from:
void tbb::interface7::task_arena::execute_impl<void, tbb::flow::interface10::graph::wait_functor const>(tbb::flow::interface10::graph::wait_functor const&) in interface_stokes.cpp.o
"tbb::task_group_context::is_group_execution_cancelled() const", referenced from:
tbb::flow::interface10::graph::wait_for_all() in interface_stokes.cpp.o
tbb::task::is_cancelled() const in interface_stokes.cpp.o
"tbb::internal::allocate_child_proxy::allocate(unsigned long) const", referenced from:
tbb::interface9::internal::allocate_sibling(tbb::task*, unsigned long) in interface_stokes.cpp.o
"tbb::internal::allocate_continuation_proxy::free(tbb::task&) const", referenced from:
operator delete(void*, tbb::internal::allocate_continuation_proxy const&) in interface_stokes.cpp.o
"tbb::internal::allocate_continuation_proxy::allocate(unsigned long) const", referenced from:
operator new(unsigned long, tbb::internal::allocate_continuation_proxy const&) in interface_stokes.cpp.o
"tbb::internal::allocate_root_with_context_proxy::free(tbb::task&) const", referenced from:
operator delete(void*, tbb::internal::allocate_root_with_context_proxy const&) in interface_stokes.cpp.o
"tbb::internal::allocate_root_with_context_proxy::allocate(unsigned long) const", referenced from:
operator new(unsigned long, tbb::internal::allocate_root_with_context_proxy const&) in interface_stokes.cpp.o
"typeinfo for tbb::task", referenced from:
typeinfo for tbb::interface9::internal::start_for<tbb::blocked_range<unsigned long>, tbb::internal::parallel_for_body<main::$_0, unsigned long>, tbb::auto_partitioner const> in interface_stokes.cpp.o
typeinfo for tbb::interface9::internal::flag_task in interface_stokes.cpp.o
"vtable for tbb::task", referenced from:
tbb::task::task() in interface_stokes.cpp.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
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]: *** [apps/interface_stokes/interface_stokes] Error 1
make[1]: *** [apps/interface_stokes/CMakeFiles/interface_stokes.dir/all] Error 2
make: *** [all] Error 2
To compile my work (saved in a different folder than TBB) I use a Cmakelists, in which I have add:
#Additional modules path for cmake
set (CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(safeguards)
set(CMAKE_CXX_FLAGS_DEBUG "-std=c++14 -g -fpermissive -fsanitize=address")
set(CMAKE_CXX_FLAGS_RELEASE "-std=c++14 -O3 -mavx -g -fpermissive")
set(CMAKE_CXX_FLAGS_RELEASEASSERT "-std=c++14 -O3 -mavx -g -fpermissive")
find_package(TBB)
if (TBB_FOUND)
include_directories(${TBB_INCLUDE_DIRS})
set(LINK_LIBS ${LINK_LIBS} ${TBB_LIBRARIES})
set(HAVE_INTEL_TBB TRUE)
endif()
include_directories("${PROJECT_BINARY_DIR}")
include_directories("${PROJECT_SOURCE_DIR}")
include_directories(src)
include_directories(contrib)
add_subdirectory(apps)
add_subdirectory(tests)
add_subdirectory(output)
In my program, there is also another folder, named cmake, in which there are some files .cmake, that actually I don't know their purposes.
I've never studied this subject and I 'm working on an already built-up code. I guess that the error is due to a bad linking of my code and the Tbb library.
Does someone know how to fix it?
Thank you so much in advance
Stefano
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
I'm not sure if I have a problem w/ requiring additional arguments to cmake, or a problem with my own Makefiles. I am trying to build and install googletest for use in one of my projects. I am running on macOS mojave, with cmake installed via Homebrew. To install googletest, I have done the following:
git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake ..
make
make install
I compile my source and test files. Here is an example command that gets generated by the Makefile for compiling a file named Point2d.cpp:
clang++ -arch x86_64 -c -std=c++11 -stdlib=libc++ -O2 -I /usr/local/include -c -o ../build/core/Point2d.o core/Point2d.cpp
I then try to link all my object files. Here is the command generated by the makefile (where main.o is the object file containing the main function for running the tests):
clang++ -arch x86_64 ../build/core/Point2d.o ../build/PointTest.o ../build/main.o -o ../bin/test -L /usr/local/lib
Resulting link error:
Undefined symbols for architecture x86_64:
"testing::InitGoogleTest(int*, char**)", referenced from:
_main in main.o
"testing::Test::SetUp()", referenced from:
vtable for Point2dTests_Constructors_Test in PointTest.o
"testing::Test::TearDown()", referenced from:
vtable for Point2dTests_Constructors_Test in PointTest.o
"testing::Test::Test()", referenced from:
testing::internal::TestFactoryImpl<Point2dTests_Constructors_Test>::CreateTest() in PointTest.o
"testing::Test::~Test()", referenced from:
Point2dTests_Constructors_Test::~Point2dTests_Constructors_Test() in PointTest.o
Point2dTests_Constructors_Test::~Point2dTests_Constructors_Test() in PointTest.o
"testing::Message::Message()", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"testing::UnitTest::GetInstance()", referenced from:
_main in main.o
"testing::UnitTest::Run()", referenced from:
_main in main.o
"testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"testing::internal::AssertHelper::~AssertHelper()", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"testing::internal::GetTestTypeId()", referenced from:
__GLOBAL__sub_I_PointTest.cpp in PointTest.o
"testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)", referenced from:
__GLOBAL__sub_I_PointTest.cpp in PointTest.o
"testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"testing::internal::IsTrue(bool)", referenced from:
testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int) in PointTest.o
testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int) in PointTest.o
"testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)", referenced from:
testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int) in PointTest.o
testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int) in PointTest.o
"testing::internal::GTestLog::~GTestLog()", referenced from:
testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int) in PointTest.o
testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int) in PointTest.o
"testing::internal::AssertHelper::operator=(testing::Message const&) const", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"typeinfo for testing::Test", referenced from:
typeinfo for Point2dTests_Constructors_Test in PointTest.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[1]: *** [../bin/test] Error 1
make: *** [test] Error 2
Solved. Please see the comments of the question, posted by #AlexDenisov
I'm working with an external code in my project which I have access to the headers and the .cc files but I don't have any access to .dylibs. I'm getting some errors, related to link of the libs, that is described bellow.
This code runs perfectly well if I run it directly from the terminal. The problem only occured when I tried to incorporate it on my own project (that have other modules) in XCode. I guess that if I add the .dylib files to XCode it will solve the problem. However, I don't have the .dylibs. How can I put this code to run?
Undefined symbols for architecture x86_64:
"FACETRACKER::IO::LoadCon(char const*)", referenced from:
mark(int, char const**) in main.o
"FACETRACKER::IO::LoadTri(char const*)", referenced from:
mark(int, char const**) in main.o
"FACETRACKER::CLM::GetViewIdx()", referenced from:
mark(int, char const**) in main.o
"FACETRACKER::FDet::~FDet()", referenced from:
FACETRACKER::Tracker::~Tracker() in main.o
FACETRACKER::Tracker::Tracker(char const*) in main.o
"FACETRACKER::Tracker::Load(char const*)", referenced from:
FACETRACKER::Tracker::Tracker(char const*) in main.o
"FACETRACKER::Tracker::Track(cv::Mat, std::__1::vector<int, std::__1::allocator<int> >&, int, int, double, double, bool)", referenced from:
mark(int, char const**) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am relatively new to C++, but I have used log4j (and it's Python clone logging). Therefore I want to use log4cxx for logging in my new C++ project.
I installed log4cxx with
brew install log4cxx
Now I need to include it in my source files. I tried, e.g.
#include "log4cxx/logger.h"
namespace EnsembleClustering {
METISGraphParser::METISGraphParser() {
// logging
log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("METISGraphParser"));
logger->setLevel(log4cxx::Level::getInfo());
this->logger = logger;
}
}
which does not seem to include enough, since this gives me the linker error
13:06:29 **** Incremental Build of configuration Debug for project EnsembleClustering ****
make all
Building file: ../src/METISGraphParser.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/METISGraphParser.d" -MT"src/METISGraphParser.d" -o "src/METISGraphParser.o" "../src/METISGraphParser.cpp"
../src/METISGraphParser.cpp: In member function 'virtual void EnsembleClustering::METISGraphParser::connectNode(EnsembleClustering::id, std::vector<unsigned int, std::allocator<unsigned int> >)':
../src/METISGraphParser.cpp:128: warning: unused variable 'deg'
../src/METISGraphParser.cpp: In member function 'virtual EnsembleClustering::Graph EnsembleClustering::METISGraphParser::parse(std::string)':
../src/METISGraphParser.cpp:112: warning: control reaches end of non-void function
Finished building: ../src/METISGraphParser.cpp
Building target: EnsembleClustering
Invoking: MacOS X C++ Linker
g++ -o "EnsembleClustering" ./src/EdgeScoring.o ./src/EdgeTripleGraphData.o ./src/EnsembleClustering.o ./src/EnsembleClusteringAlgo.o ./src/Graph.o ./src/METISGraphParser.o ./src/Matching.o ./src/Modularity.o
Undefined symbols for architecture x86_64:
"log4cxx::spi::LocationInfo::LocationInfo(char const*, char const*, int)", referenced from:
EnsembleClustering::METISGraphParser::initGraph(int, int)in METISGraphParser.o
"log4cxx::Level::getInfo()", referenced from:
EnsembleClustering::METISGraphParser::METISGraphParser()in METISGraphParser.o
EnsembleClustering::METISGraphParser::METISGraphParser()in METISGraphParser.o
"log4cxx::Level::getDebug()", referenced from:
EnsembleClustering::METISGraphParser::initGraph(int, int)in METISGraphParser.o
"log4cxx::Logger::getLogger(char const*)", referenced from:
EnsembleClustering::METISGraphParser::METISGraphParser()in METISGraphParser.o
EnsembleClustering::METISGraphParser::METISGraphParser()in METISGraphParser.o
"log4cxx::helpers::MessageBuffer::str(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
EnsembleClustering::METISGraphParser::initGraph(int, int)in METISGraphParser.o
"log4cxx::helpers::MessageBuffer::MessageBuffer()", referenced from:
EnsembleClustering::METISGraphParser::initGraph(int, int)in METISGraphParser.o
"log4cxx::helpers::MessageBuffer::~MessageBuffer()", referenced from:
EnsembleClustering::METISGraphParser::initGraph(int, int)in METISGraphParser.o
"log4cxx::helpers::MessageBuffer::operator<<(char const*)", referenced from:
EnsembleClustering::METISGraphParser::initGraph(int, int)in METISGraphParser.o
"log4cxx::helpers::ObjectPtrBase::exchange(void**, void*)", referenced from:
log4cxx::helpers::ObjectPtrT<log4cxx::Logger>::exchange(log4cxx::Logger const*)in METISGraphParser.o
"log4cxx::helpers::ObjectPtrBase::ObjectPtrBase()", referenced from:
log4cxx::helpers::ObjectPtrT<log4cxx::Logger>::ObjectPtrT()in METISGraphParser.o
"log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()", referenced from:
log4cxx::helpers::ObjectPtrT<log4cxx::Level>::~ObjectPtrT()in METISGraphParser.o
log4cxx::helpers::ObjectPtrT<log4cxx::Level>::~ObjectPtrT()in METISGraphParser.o
log4cxx::helpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT()in METISGraphParser.o
log4cxx::helpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT()in METISGraphParser.o
"log4cxx::helpers::CharMessageBuffer::operator<<(int)", referenced from:
EnsembleClustering::METISGraphParser::initGraph(int, int)in METISGraphParser.o
"log4cxx::Logger::isDebugEnabled() const", referenced from:
EnsembleClustering::METISGraphParser::initGraph(int, int)in METISGraphParser.o
"log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, log4cxx::spi::LocationInfo const&) const", referenced from:
EnsembleClustering::METISGraphParser::initGraph(int, int)in METISGraphParser.o
"typeinfo for log4cxx::helpers::ObjectPtrBase", referenced from:
typeinfo for log4cxx::helpers::ObjectPtrT<log4cxx::Level>in METISGraphParser.o
typeinfo for log4cxx::helpers::ObjectPtrT<log4cxx::Logger>in METISGraphParser.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [EnsembleClustering] Error 1
What do I need to include to get me started with log4cxx? Or do I need to explicitly link to log4cxx by modifying my Eclipse build settings? The Introduction to log4cxx isn't particularly helpful in this respect.
Here's how I managed to link log4cxx properly. Homebrew gives you a hint where it has installed the library:
cls ~/ $ brew info log4cxx
log4cxx: stable 0.10.0
http://logging.apache.org/log4cxx/index.html
Depends on: automake, libtool
/usr/local/Cellar/log4cxx/0.10.0 (182 files, 7,3M) *
https://github.com/mxcl/homebrew/commits/master/Library/Formula/log4cxx.rb
As user Component 10 has said, I need to add -L<dir>and -l<lib>to the linker line, where <dir> is /usr/local/Cellar/log4cxx/0.10.0/lib/and <lib> is the library name (not filename) log4cxx.
In Eclipse, I needed to edit the following settings:
To make this slightly simpler you can do
brew link log4cxx
It'll create the symlinks to the libraries in /usr/local/lib and /usr/local/include which are usually in the default linker/include search paths.
You'll still need to specify -llog4cxx.
I'm trying to use glfw 2.7.5 on my mac with xcode but I'm getting the following errors:
Undefined symbols for architecture i386:
"_glfwGetKey", referenced from:
Game::run() in Game.o
RedScene::update(float, bool) in main.o
"_glfwGetWindowParam", referenced from:
Game::run() in Game.o
"_glfwInit", referenced from:
Window::Window() in Window.o
"_glfwOpenWindow", referenced from:
createWindow(int, int, int, int, int, int, int, int) in Window.o
"_glfwOpenWindowHint", referenced from:
Window::Window() in Window.o
"_glfwPollEvents", referenced from:
Game::run() in Game.o
"_glfwSetKeyCallback", referenced from:
createWindow(int, int, int, int, int, int, int, int) in Window.o
"_glfwSetMouseButtonCallback", referenced from:
createWindow(int, int, int, int, int, int, int, int) in Window.o
"_glfwSetMousePosCallback", referenced from:
createWindow(int, int, int, int, int, int, int, int) in Window.o
"_glfwSetMouseWheelCallback", referenced from:
createWindow(int, int, int, int, int, int, int, int) in Window.o
"_glfwSetWindowTitle", referenced from:
Window::setCaption(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Window.o
"_glfwSwapBuffers", referenced from:
RedScene::update(float, bool) in main.o
"_glfwSwapInterval", referenced from:
createWindow(int, int, int, int, int, int, int, int) in Window.o
"_glfwTerminate", referenced from:
Window::~Window() in Window.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've read this Problems using GLFW and XCode : won't compile and several other links on the internet but I can't find a solution.
I've set the Cocoa framework, the OpenGL framework and libglfw.a (which I compiled using "sudo make cocoa-install"), in the linker flags I set -lgflw and I'm building for 32-bit Intel. At first I was building for a 64-bit but I think GLFW doesn't support that on Mac yet (I was getting joystick file errors), the error changes when I compile for 32-bit and it can't find the functions I'm using. Any idea what I could do to fix this?
Most likely you have built libglfw.a for 64 bit and so you get link errors when you try to use it in a 32 bit app. You can either rebuild libglfw.a for 32 bit (or as a "fat" 32 bit and 64 bit library), or you could just build your app as 64 bit.
Note that in recent version of Mac OS X and Xcode, gcc builds 64 bit code by default, so you need to specify -m32 on the command line to get 32 bit code. How you do this in practice depends on the makefile for libglfw.a - there may well be an ARCH or other symbol that you can specify on the command line to force a 32 bit build.