System information: Ubuntu 20.04, yaml-cpp 0.7.0, gcc version 9.4.0, compiled by CMake
Problem hint:
Either compile error:
/usr/bin/ld: CMakeFiles/test_yaml.dir/test/read_yaml.cpp.o: in function `main':
/home/kin/workspace/EDOMap/test/read_yaml.cpp:14: undefined reference to `YAML::LoadFile(std::string const&)'
/usr/bin/ld: CMakeFiles/test_yaml.dir/test/read_yaml.cpp.o: in function `YAML::detail::node_ref::set_scalar(std::string const&)':
/usr/local/include/yaml-cpp/node/detail/node_ref.h:37: undefined reference to `YAML::detail::node_data::set_scalar(std::string const&)'
/usr/bin/ld: CMakeFiles/test_yaml.dir/test/read_yaml.cpp.o: in function `YAML::Node::Scalar() const':
/usr/local/include/yaml-cpp/node/impl.h:169: undefined reference to `YAML::detail::node_data::empty_scalar()'
/usr/bin/ld: CMakeFiles/test_yaml.dir/test/read_yaml.cpp.o: in function `YAML::detail::node& YAML::detail::node_data::get<char [4]>(char const (&) [4], std::shared_ptr<YAML::detail::memory_holder>)':
Either compiled, run segmentation fault
segmentation fault
For a brief version of the solution, refer to the issue comment and add this on top of the .cpp:
#define YAML_CPP_STATIC_DEFINE
Or Open3D reason, recompile it, see the second part for details
Possible reasons [static compilation]
The reason for the compilation error is actually because another program sub-library of mine was compiled with gcc 10.0+, so my normal compilation instructions are:
mkdir build && cd build
cmake .. -D CMAKE_CXX_COMPILER=g++-10 && make
file structure:
➜ test_ws tree -L 2
.
├── build
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── Makefile
│ └── test_yaml
├── CMakeLists.txt
└── test.cpp
Then the main.cpp file looks like this:
// STL
#include <iostream>
#include <glog/logging.h>
#include "yaml-cpp/yaml.h"
int main(int argc, char* argv[]){
// Setup logging.
google::InitGoogleLogging(argv[0]);
google::InstallFailureSignalHandler();
FLAGS_colorlogtostderr = true;
google::SetStderrLogging(google::INFO);
// YAML::Node node = YAML::LoadFile("assets/config.yaml");
YAML::Node node = YAML::Load("foo: bar\nx: 2");
// for(auto dict: config){
// std::string test_path = config["point_cloud_data_dir"].as<std::string>();
LOG(INFO) << node["foo"].as<std::string>();
// auto debug_test = config["debug_print"];
// LOG(INFO) << test_path;
// LOG(INFO) << debug_test;
// }
}
The complete CMakeLists.txt is:
cmake_minimum_required(VERSION 3.14)
project(edomap
VERSION 1.0.0
DESCRIPTION "EDOMap"
LANGUAGES CXX
)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(default_build_type "Release")
include_directories(include)
find_package(Glog REQUIRED)
find_package(gflags REQUIRED)
find_package(Eigen3 REQUIRED)
set(LOG_LIB glog::glog gflags)
# Declaration of package required
find_package(yaml-cpp REQUIRED)
add_executable(test_yaml main.cpp)
target_link_libraries(test_yaml ${LOG_LIB} yaml-cpp)
. . . . I can't reproduce the problem holl shit... Even if it is deleted, it doesn't seem to report an error? ? me? ?
But to sum it up:
-
The initial attempt did not go
cmake .. && make
higher compiler can be compiled through -
Running the code after the progress attempt passes will report a segment fault
-
After searching around to no avail, I saw the static problem in the issue and added it directly to the beginning of .cpp
-
Oh hoo, then it's okay, it's okay, it's okay? ? -> Even if I try to reproduce the problem next time, I will not be able to reproduce it... I am... stupid
But when I reappeared, I found that make install is different from the previous impression. It is static automatic compilation. CXX static library
I remember that it didn’t seem to be the case before.
[ 83%] Linking CXX static library libyaml-cpp.a
[ 83%] Built target yaml-cpp
Consolidate compiler generated dependencies of target parse
Further [Open3D reason]
Finally, I found out that it was Open3D's fault! ! ! issue link
But obviously the last person said that it is already the default option... Could it be the feud between open3d and yaml-cpp?
emmm I forgot how my computer's Open3D came from before, but it seems that just pull the latest v0.16.0, the installation method is as follows:
git clone --recursive --depth 1 --branch v0.16.0 https://github.com/isl-org/Open3D
cd Open3D && source util/scripts/install-deps-ubuntu.sh
mkdir build && cd build
cmake -DBUILD_EIGEN3=ON -DBUILD_GLEW=ON -DBUILD_GLFW=ON -DBUILD_JSONCPP=ON -DBUILD_PNG=ON -DGLIBCXX_USE_CXX11_ABI=ON -DPYTHON_EXECUTABLE=/usr/bin/python -DBUILD_UNIT_TESTS=ON ..
make -j${nproc}
sudo make install
Well... It's the Open3D pot that caused me to look for it for so long