Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ld: symbol(s) not found for architecture x86_64 #456

Closed
juev opened this issue Jan 7, 2017 · 7 comments
Closed

ld: symbol(s) not found for architecture x86_64 #456

juev opened this issue Jan 7, 2017 · 7 comments

Comments

@juev
Copy link

juev commented Jan 7, 2017

Sorry for stupid question.

I trying to use yaml-cpp for parsing simple yaml file.
OS: macOS Siera 10.12.2

$ g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

main.cpp:

#include <iostream>
#include <yaml-cpp/yaml.h>

using namespace std;

int main() {
    YAML::Node config = YAML::LoadFile("config.yaml");

    const std::string username = config["username"].as<std::string>();
    const std::string password = config["password"].as<std::string>();

    cout << "username: " << username << endl
         << "password: " << password << endl;

    return 0;
}

When I trying compile this code:

$ g++ main.cpp -o yaml -v

I get error:

Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 274.2 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Library/Developer/CommandLineTools/usr/bin/../lib/clang/8.0.0 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/juev/Projects/CPP -ferror-limit 19 -fmessage-length 158 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/j_/mn1l90j15f92df2p9j_qdfcr0000gn/T/main-015037.o -x c++ main.cpp
clang -cc1 version 8.0.0 (clang-800.0.42.1) default target x86_64-apple-darwin16.3.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/bin/../lib/clang/8.0.0/include
 /Library/Developer/CommandLineTools/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.12.0 -o yaml /var/folders/j_/mn1l90j15f92df2p9j_qdfcr0000gn/T/main-015037.o -lc++ -lSystem /Library/Developer/CommandLineTools/usr/bin/../lib/clang/8.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "YAML::detail::memory_holder::merge(YAML::detail::memory_holder&)", referenced from:
      YAML::detail::node& YAML::detail::node_data::convert_to_node<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, boost::shared_ptr<YAML::detail::memory_holder>) in main-015037.o
  "YAML::detail::memory::create_node()", referenced from:
      YAML::detail::memory_holder::create_node() in main-015037.o
  "YAML::detail::node_data::set_scalar(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      YAML::detail::node_ref::set_scalar(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main-015037.o
  "YAML::detail::node_data::empty_scalar", referenced from:
      YAML::Node::Scalar() const in main-015037.o
  "YAML::detail::node_data::mark_defined()", referenced from:
      YAML::detail::node_ref::mark_defined() in main-015037.o
  "YAML::detail::node_data::convert_to_map(boost::shared_ptr<YAML::detail::memory_holder>)", referenced from:
      YAML::detail::node& YAML::detail::node_data::get<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, boost::shared_ptr<YAML::detail::memory_holder>) in main-015037.o
  "YAML::detail::node_data::insert_map_pair(YAML::detail::node&, YAML::detail::node&)", referenced from:
      YAML::detail::node& YAML::detail::node_data::get<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, boost::shared_ptr<YAML::detail::memory_holder>) in main-015037.o
  "YAML::detail::node_data::set_null()", referenced from:
      YAML::detail::node_ref::set_null() in main-015037.o
  "YAML::LoadFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      _main in main-015037.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Whats wrong and how I can resolve this problem?

@jbeder
Copy link
Owner

jbeder commented Jan 7, 2017

Add -lyaml-cpp to your compile command.

@jdluk87
Copy link

jdluk87 commented Dec 1, 2017

I am having the same problem @jbeder when I do cmake ; make. When using cmake where exactly should I add -lyaml-cpp?

@KitsuneRal
Copy link

KitsuneRal commented Dec 1, 2017

I add yaml-cpp to target_link_libraries in my CMakeLists.txt. Disclaimer: I'm building yaml-cpp as a submodule, so there's add_subdirectory(yaml-cpp) before that. But at the same rate the already built library can be in paths ld searches.

@jdluk87
Copy link

jdluk87 commented Dec 1, 2017

@KitsuneRal thanks, same issue. Let me paste here the CMakeLists.txt. To give you some context, this is a C++ project that use GTEST for testing. YAML is only a dependency for my code.

cmake_minimum_required(VERSION 2.8)
project(reranker C CXX)
include(CheckCXXCompilerFlag)
include(ExternalProject)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -std=c++14 -Wall -fPIC")

option(USE_GTEST "Use google test for unit test" ON)

if(DEFINED OSX)
    set(CMAKE_MACOSX_RPATH 1)
endif()

#---------------------------------------
# source 
#---------------------------------------

set(MODULES
  base 
  parser
)

foreach(module ${MODULES})
  set(moduleDir ${CMAKE_CURRENT_SOURCE_DIR}/src/${module})

  file(GLOB cppFiles ${moduleDir}/*.cpp)
  set(SRC_FILES ${SRC_FILES} ${cppFiles})
endforeach()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

#---------------------------------------
# dependencies
#---------------------------------------
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/yaml/include)
add_subdirectory(yaml)

# yaml
ExternalProject_Add(yaml
    GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
    CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/build
    PREFIX "${CMAKE_CURRENT_BINARY_DIR}"
  )

# project setup
add_library (${PROJECT_NAME} SHARED ${SRC_FILES})
target_link_libraries(${PROJECT_NAME} ${EXTRA_LIBS})
target_link_libraries(${PROJECT_NAME} yaml-cpp)
add_dependencies(${PROJECT_NAME} yaml)

message("use_gtest=${USE_GTEST}")
if (USE_GTEST)
  message("gtest is used")
  #---------------------------------------
  # gtest
  #---------------------------------------
  ExternalProject_Add(googletest
    GIT_REPOSITORY https://github.com/google/googletest.git
    CMAKE_ARGS -Dgtest_force_shared_crt=ON
    PREFIX "${CMAKE_CURRENT_BINARY_DIR}"
    INSTALL_COMMAND ""
  )
  
  ExternalProject_Get_Property(googletest source_dir)
  include_directories(${source_dir}/googletest/include)
  include_directories(${source_dir}/googlemock/include)
  
  ExternalProject_Get_Property(googletest binary_dir)
  set(GTEST_LIBS_DIR ${binary_dir}/googlemock/gtest)
  set(GMOCK_LIBS_DIR ${binary_dir}/googlemock)
  
  #---------------------------------------
  # testing
  #---------------------------------------
  enable_testing()

  set(TEST_DIRS
    base 
    parser
  )

  foreach(dirName ${TEST_DIRS})
    set(testName ${PROJECT_NAME}-test-${dirName})
    set(testLabel test-${dirName})
    set(dirPath ${CMAKE_CURRENT_SOURCE_DIR}/test/${dirName})
    file(GLOB testFiles ${dirPath}/*.cpp)
    add_executable(${testName} ${SRC_FILES} ${testFiles})
    add_dependencies(${testName} googletest)

    target_link_libraries(${testName}
      ${GTEST_LIBS_DIR}/libgtest.a
      ${GTEST_LIBS_DIR}/libgtest_main.a
      ${GMOCK_LIBS_DIR}/libgmock.a
      ${GMOCK_LIBS_DIR}/libgmock_main.a
    )

    target_link_libraries(${testName} ${CMAKE_THREAD_LIBS_INIT} ${EXTRA_LIBS})
    add_test(${testLabel} ${testName} WORKING_DIRECTORY ${dirPath})
  endforeach()
endif()

@KitsuneRal
Copy link

Can't say anything about this: things look pretty much in place. Maybe check your environment and whether yaml-cpp is compiled with proper flags. I'd also check with ldd that the mentioned symbols are indeed in the library. Also, there might be some rogue installation of yaml-cpp in a path ld uses, and ld stumbles over it. This is just a couple of ideas for troubleshooting.

Maybe one sidenote: I'm not sure if you really need add_dependencies(${PROJECT_NAME} yaml), since target_link_libraries already does the same, if I don't mistake. I'm not sure though.

@seisowl
Copy link

seisowl commented Jan 31, 2018

This happened multi-times to me (with different machines) when I use apt-get to install the yaml-cpp package from Ubuntu. Clone from the git, build and install works (sometimes need a particular version). Make sure you uninstall the package. One of my friends somehow get it in /opt/... directory and it won't work until I found the files and deleted them manually... Today I installed the next generation version 0.6 and it worked (better experience probably because it no longer requires BOOST)!

@dbl001
Copy link

dbl001 commented Aug 25, 2022

I am getting this error with 'yaml' compiling SuperCollider on my iMac.

Undefined symbols for architecture x86_64:
  "YAML::BadConversion::~BadConversion()", referenced from:
      YAML::TypedBadConversion<bool>::~TypedBadConversion() in libsclang.a(SC_LanguageConfig.o)

supercollider/supercollider#5852

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants