1

Context : I am following this guide to generate my Visual Studio project with the Point Cloud Library PCL, it seems to be the only way to use it.

Problem : I have realised that with this method I can not include other libraries like the Bitmap_image.hpp or even the string.h

I've tried :

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(MY_GRAND_PROJECT)
find_package(PCL 1.3 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcd_write_test pcd_write.cpp)
target_link_libraries(pcd_write_test ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES} ${string})

The result:

It generates the project. PCL works perfectly and the line

#include <string>

does not show error.

But

string a;

throws "Error C2065 'string': undeclared identifier" and the same happens with other libraries.

Any solution?

Daniel Amaya
  • 113
  • 2
  • 10

1 Answers1

3

This is (basic) C++ knowledge and has nothing to do with any part of the build system.

#include <string> pulls in the C++ Standard Library, specifically the container std::string. As long as your compiler knows you are compiling C++ (and Visual Studio knows this from the .cpp file extension), then it will link a version of the C++ Standard Library for you automatically.

All your calls to these parts of the C++ Standard Library need to be prefixed with std:: or you need a using namespace std; somewhere in your code (the second is generally not recommended though).

In other words, remove ${string}, since it was not there in the original CMakeLists.txt file you are following (and also means nothing) and use std::string in your source code etc.

As for Bitmap_image.hpp, you need to indicate where to find it. If it is part of PCL, then that should already be working.

If it is a different library, you will need to learn the basics of CMake to add these libraries. Hint: CMake commands add_library() and target_include_directories() and target_link_libraries(). Also, target_compile_options() and target_compile_definitions() could be useful.

A good modern introduction to CMake is by Daniel Pfeifer.

utopia
  • 1,477
  • 8
  • 7