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

have problems add open3d into C++ project #2894

Closed
HugeKangroo opened this issue Jan 14, 2021 · 7 comments
Closed

have problems add open3d into C++ project #2894

HugeKangroo opened this issue Jan 14, 2021 · 7 comments
Assignees
Labels
build/install Build or installation issue

Comments

@HugeKangroo
Copy link

HugeKangroo commented Jan 14, 2021

Describe the bug
Hello, I created a simple C++ project with yaml-cpp. This project can be compiled until I add open3d into my CMakeLists.txt.
the output error messages are:

/usr/bin/ld: CMakeFiles/o3d.dir/main.cpp.o: in function `main':
/home/dusty/Documents/Geometory3D/main.cpp:6: undefined reference to `YAML::LoadFile(std::string const&)'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/o3d.dir/build.make:106: o3d] Error 1
make[2]: *** [CMakeFiles/Makefile2:96: CMakeFiles/o3d.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:103: CMakeFiles/o3d.dir/rule] Error 2
make: *** [Makefile:138: o3d] Error 2

Is there something missing or wrong with my CMakeLists.txt ? thanks in advance.

To Reproduce
here is my main.cpp:

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

int main(int, char**) {
        YAML::LoadFile("./config.yaml");
        const std::vector<std::string> files = {
        "../data/models/ROBOX_0.pcd",
        "../data/models/ROBOX_1.pcd",
        "../data/models/ROBOX_2.pcd",
        "../data/models/ROBOX_3.pcd"
    };
    std::vector<std::shared_ptr<open3d::geometry::Geometry>> clouds;
    for(const std::string &file : files){
        auto cloud_ptr = open3d::io::CreatePointCloudFromFile(file);
        open3d::visualization::DrawGeometries({cloud_ptr}, "TestPCDFileFormat", 1920, 1080);
    }

}

and CMakeLists.txt:

cmake_minimum_required(VERSION 3.17)
project(o3d VERSION 0.1.0)

find_package(yaml-cpp REQUIRED)
include_directories("${YAML_CPP_INCLUDE_DIR}")
link_libraries("${YAML_CPP_LIBRARIES}")

find_package(Open3D REQUIRED)
include_directories(${Open3D_INCLUDE_DIRS})
link_libraries(${Open3D_LIBRARIES})

add_executable(o3d main.cpp)

Environment (please complete the following information):

  • Operating system: Ubuntu 18.04

  • Open3D version: 0.12.0

  • Is this remote workstation?: no

  • How did you install Open3D?: build from source

  • Compiler version (if built from source): gcc 9.3.0

@HugeKangroo HugeKangroo changed the title add open3d to c++ project failed have problems add open3d into C++ project Jan 14, 2021
@theNded
Copy link
Contributor

theNded commented Jan 14, 2021

Looks like a YAML linking issue. Does this work?

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

int main(int, char**) {
        YAML::LoadFile("./config.yaml");
        const std::vector<std::string> files = {
        "../data/models/ROBOX_0.pcd",
        "../data/models/ROBOX_1.pcd",
        "../data/models/ROBOX_2.pcd",
        "../data/models/ROBOX_3.pcd"
    };
}

@HugeKangroo
Copy link
Author

HugeKangroo commented Jan 16, 2021

Thank you for your advice. I have tried it and get same messages:

[build] /usr/bin/ld: CMakeFiles/o3d.dir/main.cpp.o: in function `main':
[build] /home/dusty/Documents/Geometory3D/build/../main.cpp:6: undefined reference to `YAML::LoadFile(std::string const&)'
[build] collect2: error: ld returned 1 exit status
[build] ninja: build stopped: subcommand failed.
[build] Build finished with exit code 1

I also found that if I change link_libraries(${Open3D_LIBRARIES}) to link_libraries(Open3D), the programme will get error:

/usr/bin/ld: CMakeFiles/o3d.dir/main.cpp.o: in function `main':
/home/dusty/Documents/Geometory3D/main.cpp:15: undefined reference to `open3d::io::CreatePointCloudFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
/usr/bin/ld: /home/dusty/Documents/Geometory3D/main.cpp:16: undefined reference to `open3d::visualization::DrawGeometries(std::vector<std::shared_ptr<open3d::geometry::Geometry const>, std::allocator<std::shared_ptr<open3d::geometry::Geometry const> > > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int, int, int, bool, bool, bool, Eigen::Matrix<double, 3, 1, 0, 3, 1>*, Eigen::Matrix<double, 3, 1, 0, 3, 1>*, Eigen::Matrix<double, 3, 1, 0, 3, 1>*, double*)'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/o3d.dir/build.make:105: o3d] Error 1
make[2]: *** [CMakeFiles/Makefile2:96: CMakeFiles/o3d.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:103: CMakeFiles/o3d.dir/rule] Error 2
make: *** [Makefile:138: o3d] Error 2

I also tried other library like fcl, It seems the compilation will get wrong after linking the open3d libraries.

Just for my opinion, I guess there is something wrong with CMakeLists.txt or Open3D .

@HugeKangroo
Copy link
Author

HugeKangroo commented Jan 18, 2021

Maybe this is the same issue as in: #2286 and #2656

@sanskar107 sanskar107 added the build/install Build or installation issue label Jan 19, 2021
@SoulProtagonist
Copy link

instead of "link_libraries(Open3D)" try "link_libraries(Open3D::Open3D)"

@HugeKangroo
Copy link
Author

the sentence link_libraries(${Open3D_LIBRARIES}) is equal to link_libraries(Open3D::Open3D)

@cbenitez81
Copy link

Seems that this #2286 (comment) solves the problem

@ssheorey
Copy link
Member

I can verify that @cbenitez81 's suggestion resolves this. Also, with PR #4387 this is no longer needed. Note that if you need PyTorch Ops or TensorFlow Ops, you will need to build PyTorch / TensorFlow from source with the new CXX11_ABI. This only affects GCC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build/install Build or installation issue
Projects
None yet
Development

No branches or pull requests

6 participants