fatal error: 'google/protobuf/port_def.inc' file not found - c++

I am using CLion cmakelist.txt to compile but receive the following error. The program compiled with g++ but somehow lacks dependency when I am using cmake. anyone know how to solve this?
cmake_minimum_required(VERSION 3.19)
project(CTCWordBeamSearch_master)
find_package(PkgConfig)
pkg_check_modules(TensorFlow REQUIRED tensorflow)
link_directories(${TensorFlow_LIBRARY_DIRS})
include_directories(${TensorFlow_INCLUDE_DIRS})
add_compile_definitions(${TensorFlow_CFLAGS_OTHER})
set(CMAKE_CXX_STANDARD 14)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(.)
include_directories(cpp)
include_directories(cpp/proj)
include_directories(cpp/src)
include_directories(cpp/src/pybind)
include_directories(cpp/src/pybind/pybind11)
include_directories(cpp/src/pybind/pybind11/detail)
include_directories(cpp/src/utfcpp)
include_directories(cpp/src/utfcpp/utf8)
include_directories(data)
include_directories(doc)
include_directories(np)
include_directories(py)
include_directories(tf)
add_executable(CTCWordBeamSearch_master
...
)
target_link_libraries(CTCWordBeamSearch_master ${PYTHON_LIBRARIES})
target_link_libraries(CTCWordBeamSearch_master ${TensorFlow_LIBRARIES})

Related

C++ Linking a custom library built from source (CMakeLists.txt)

I built Open3D from source into a /home/user/custom_location/Open3D/build
I have a project with a dependency on Open3D and a CMakeLists.txt like this:
cmake_minimum_required(VERSION 3.12)
project(graph_filter)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)
# Pybind11
find_package(pybind11 REQUIRED)
# OpenMP
find_package(OpenMP REQUIRED)
# Eigen
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
# Open3D
list(APPEND CMAKE_INSTALL_PREFIX "~/libraries/")
find_package(Open3D HINTS ${CMAKE_INSTALL_PREFIX}/lib/CMake)
list(APPEND Open3D_LIBRARIES dl)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Open3D_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${Open3D_EXE_LINKER_FLAGS}")
include_directories(${Open3D_INCLUDE_DIRS})
link_directories(${Open3D_LIBRARY_DIRS})
pybind11_add_module(
graph_filter
wrapper.cpp
)
target_link_libraries(graph_filter PRIVATE ${Open3D_LIBRARIES} Eigen3::Eigen OpenMP::OpenMP_CXX)
How can I link it? When I run
INSTALL_DIR=/home/user/custom_location/Open3D/build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}```
I am getting:
Could NOT find Open3D (missing: Open3D_DIR)
fatal error: Open3D/Open3D.h: No such file or directory
2 | #include <Open3D/Open3D.h>
What is more confusing is the contents of Open3D/build folder after building from source.
I just want to resolve this dependency on Open3D. Thanks for any help!!!

How do I add OpenCV to LD_LIBRARY path in linux?

I used this link to install OpenCV.
What works:
1.OpenCV works fine with python (running from terminal).
2.I can import opencv libraries in a single C++ program.
What does not work :
When the code is spread across multiple and you need to build it using CMake.
Here's my CmakeLists.txt :
1.cmake_minimum_required(VERSION 3.9)
2.project(Image_processing)
3.set(CMAKE_CXX_STANDARD 14)
4.find_package(OpenCV REQUIRED)
5.include_directories(/home/user/opencv/build)
6.add_executable(main main.cpp)
7.target_link_libraries(project_name ${OpenCV_LIBS})
Errors (can regenerate them by commenting lines 4,5 and 7 in above CMake file):
undefined reference to OpenCV functions.
CMake Error at CMakeLists.txt:7 (target_link_libraries):
Cannot specify link libraries for target "Image_processing" which is not
built by this project.
Correct it with:
cmake_minimum_required(VERSION 3.5)
project(Image_processing)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS})
In your CMakeLists.txt, the exe-name is not matching with the target-link-name. I modify the line, then it works on my PC.
The CMakeLists.txt of an OpenCV Project:
cmake_minimum_required(VERSION 3.5)
project(Image_processing)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV REQUIRED)
#include_directories(/home/user/opencv/build)
add_executable(Image_processing main.cpp)
target_link_libraries(Image_processing ${OpenCV_LIBS})

CMake error: Imported targets not available for Boost version 106300

I am trying to use uint512_t in a boost library located in:
multiprecision/cpp_int.hpp
however, when I try to include my boost library through CMake:
cmake_minimum_required(VERSION 3.6)
project(BoostTest)
set(CMAKE_CXX_STANDARD 11)
set(BOOSTROOT "/usr/local/Cellar/boost/1.63.0/include")
find_package(Boost REQUIRED)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
endif()
include_directories(${Boost_INCLUDE_DIR})
set(SOURCE_FILES main.cpp)
add_executable(BoostTest ${SOURCE_FILES})
I receive the following error message when compiling:
error: unknown type name 'uint512_t'
I don't know what the problem is. I even included:
"boost/multiprecision/cpp_int.hpp"
Keeping everything else the same in main.cpp, all that was needed was:
using namespace boost::multiprecision

Building wxWidgets 3.1.0 on CLion (Ubuntu)

I am currently trying to build wxWidgets-3.1.0 on a CLion 1.3 project. I use Ubuntu 16.04 (64 bit). Basically, I edited the CMakeLists.txt file like this:
cmake_minimum_required(VERSION 3.5)
project(WxProva)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules"
${CMAKE_MODULE_PATH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(WxProva ${SOURCE_FILES})
find_package(wxWidgets)
include_directories(${wxWidgets_INCLUDE_DIRS})
target_link_libraries(WxProva ${wxWidgets_LIBRARIES})
The "External Libraries" section also shows me wxWidgets, but when it comes to write some lines on my main.cpp, everything related with the library seems to be unreachable by the compiler (it's all written in red, like an error). Anyway, if I try to compile, that's the result:
/home/federico/ClionProjects/WxProva/main.cpp:2:35: fatal error: wxWidgets-3.1.0/include: File o directory non esistente
compilation terminated.
Which is like "File or directory doesn't exists."
How can I fix this?
After some experiments here solution. You can just copy it and change some information and ready to build and run.
cmake_minimum_required(VERSION 3.7)
project(Your_Project_Name) //any name for your project
set(CMAKE_CXX_STANDARD 11)
set(wxWidgets_ROOT_DIR </usr/include/wx-3.0-unofficial>) // here I am giving where to search for wxwidgets library. it can be different for you
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})
set(SOURCE_FILES main.cpp)
add_executable(FirstC ${SOURCE_FILES})
target_link_libraries(FirstC ${wxWidgets_LIBRARIES})
For more Information read https://wiki.wxwidgets.org/CMake
Edit 1
Here you shouldn't even add some compile and link config (wx-config --cxxflags and wx-config --libs) as it is necessary in NetBeans
Here is example configuration for macOS 10.14.4 (Mojave) and CLion 2019.1
(/usr/local is folder where I installed wxWidgets)
cmake_minimum_required(VERSION 3.14)
project(wx1Test)
set(CMAKE_CXX_STANDARD 14)
set(wxWidgets_ROOT_DIR </usr/local/include/wx-3.1>)
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})
set(SOURCE_FILES main.cpp)
add_executable(wx1Test ${SOURCE_FILES})
target_link_libraries(wx1Test ${wxWidgets_LIBRARIES})

QGLViewer simpleViewer example built with cmake not running

I'm trying to familiarize with QGLViewer (http://libqglviewer.com/) so I installed it (on Ubuntu 14.04) and I'm trying to run the simpleViewer (which is a provided example). Now, the code can be built using qmake, but I want to compile the code with cmake so I wrote the following CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
PROJECT(simple_viewer)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
FIND_PACKAGE(OpenGL REQUIRED)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE})
FIND_PACKAGE(QGLViewer REQUIRED)
INCLUDE_DIRECTORIES(${QGLVIEWER_INCLUDE_DIR})
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
INCLUDE_DIRECTORIES(${QT_INCLUDES})
ADD_EXECUTABLE(${PROJECT_NAME} main.cpp simpleViewer.cpp)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARIES} ${QGLVIEWER_LIBRARY})
I'm able to build the project but when I launch the executable this is the error I get:
dede#dede-P35V2:~/src/simple_viewer/build$ ./simple_viewer
*** Error in `./simple_viewer': realloc(): invalid pointer: 0x00007f64d34df840 *** Aborted
I'd be glad if someone could explain me what's wrong!
Thanks!
worked this way:
cmake_minimum_required(VERSION 2.6)
PROJECT(simple_viewer)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
FIND_PACKAGE(OpenGL REQUIRED)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE})
FIND_PACKAGE(QGLViewer REQUIRED)
INCLUDE_DIRECTORIES(${QGLVIEWER_INCLUDE_DIR})
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
INCLUDE_DIRECTORIES(${QT_INCLUDES})
ADD_EXECUTABLE(${PROJECT_NAME} main.cpp simpleViewer.cpp)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
${QGLVIEWER_LIBRARY}
${QT_QTXML_LIBRARY}
${QT_QTOPENGL_LIBRARY}
${QT_QTGUI_LIBRARY}
${QT_QTCORE_LIBRARY}
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
)