CPR cross-compile: No such file or directory error - c++

I'm trying to compile cpr for android and run the sample project, but it gives an error when i run it on my 64 bit phone.
/system/bin/sh: ./AndroidProject3: No such file or directory
https://github.com/libcpr/cpr
cmake_minimum_required(VERSION 3.22)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 29)
set(CMAKE_SYSTEM_PROCESSOR arm64-v8a)
set(CMAKE_ANDROID_NDK "/home/coret/android-ndk/")
set(CMAKE_ANDROID_STL_TYPE c++_static)
set(CMAKE_TOOLCHAIN_FILE "/home/coret/android-ndk/build/cmake/android.toolchain.cmake")
project(AndroidProject3)
include(FetchContent)
FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git
GIT_TAG beb9e98806bb84bcc130a2cebfbcbbc6ce62b335) # The commit hash for 1.7.2. Replace with the latest from: https://github.com/libcpr/cpr/releases
FetchContent_MakeAvailable(cpr)
add_executable(AndroidProject3 main.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE cpr::cpr -static)
#include <cpr/cpr.h>
int main(int argc, char** argv) {
cpr::Response r = cpr::Get(cpr::Url{"https://api.github.com/repos/whoshuu/cpr/contributors"},
cpr::Authentication{"user", "pass"},
cpr::Parameters{{"anon", "true"}, {"key", "value"}});
r.status_code; // 200
r.header["content-type"]; // application/json; charset=utf-8
r.text; // JSON text string
return 0;
}
How do I solve it?

Related

SDL2 program on windows cannot start (runnerw.exe: CreateProcess failed with error 193: %1)

I downloaded SDL2 release edition from: sdl-github: SDL2-devel-2.24.0-mingw.zip.
The OS is windows 10.
Compile environment is MINGW64.
IDE is clion.
My CMakeLists.txt file is
cmake_minimum_required(VERSION 3.20)
project(sdl_test)
set(CMAKE_CXX_STANDARD 20)
list(APPEND CMAKE_PREFIX_PATH "D:/lib/SDL2-2.24.0")
MESSAGE(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
find_package(sdl2 CONFIG REQUIRED)
MESSAGE(STATUS "SDL2_INCLUDE_DIRS is ${SDL2_INCLUDE_DIRS}")
MESSAGE(STATUS "SDL2_LIBRARIES is ${SDL2_LIBRARIES}")
include_directories(${SDL2_INCLUDE_DIRS})
add_executable(sdl_test main.cpp)
target_link_libraries(sdl_test ${SDL2_LIBRARIES}-static)
target_link_libraries(sdl_test ${SDL2_LIBRARIES}main)
The main.cpp file is:
extern "C"{
#include <SDL.h>
};
#include <stdio.h>
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
printf("SDL initialize ok!");
SDL_Quit();
getchar();
return 0;
}
The program can be compiled with no errors but when running it turns that:
runnerw.exe: CreateProcess failed with error 193: %1

Moving from QT 5.12.8 to 5.15.2 MOC fails

We try to mov to the latest Qt 5 LTSB (5.15.2) from our working base Qt 5.12.8 but ran into MOC errors:
The moc process failed to compile
   "SRC:GenericForm.h"
into
   "SRC:moc_GenericForm.cpp"
Output
   SRC:/workspace/NBCI2/src/base/base_language.(9): Parse error at "{"
The problem occours whith every Qt build greater 5.12.x what do we missing? What is changed on moc between 5.12.x and later?
Build system is cmake
base_language is include by some of the include headers.
GenericForm.h:
#pragma once
#include "host.h"
#include "qt_type_defines.h"
#include <qwidget.h>
#include "qt_in_scheduler.h"
#include "qt_out_scheduler.h"
#include "GenericBaseForm.h"
namespace qt
{
using namespace nbc;
class GenericForm : public GenericBaseForm
{
Q_OBJECT
public:
GenericForm(host::ihost * h, const GenericFormConfig & cfg, safe_bool & Shutdown, rmutex & form_creation_mtx);
virtual ~GenericForm();
virtual void SetTitleError(bool on);
virtual void SetTitle(str_cref title_str);
virtual void SetHintText(str_cref hint_str);
virtual bool AllowHide();
virtual void OnLanguageChange(lang_t)
};
}
base_language:
#ifndef BASE_LANGAUAGE_H
#define BASE_LANGAUAGE_H
#include "base.h"
namespace base
{
enum struct lang_t : char
{
default = -1,
english = 0,
german = 1,
french = 2,
};
base::str_t to_string(lang_t);
lang_t from_string(base::str_cref);
}
#endif
CMake.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 3.17.0 FATAL_ERROR)
SET(VERSION_MAJOR 1)
SET(VERSION_MINOR 0)
SET(VERSION_PATCH 0)
SET(PROJECT_NAME "lib_GenericForms")
# find Qt5 and required components
FIND_PACKAGE(Qt5 COMPONENTS REQUIRED Core Gui Widgets )
#need this to include the auto generated ui_mainwindow.h
#file from the qt5_wrap_ui call below.
IF(CMAKE_VERSION VERSION_LESS "3.7.0")
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
ENDIF()
INCLUDE_DIRECTORIES(
)
ADD_DEFINITIONS( -DBUILD_STATIC -DQT_SUPPORT_LIB
)
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTOUIC ON)
SET(CMAKE_AUTORCC ON)
SET(ENVIRONMENT_EXTENSION_DEBUG
${ENVIRONMENT_EXTENSION}
)
SET(ENVIRONMENT_EXTENSION_RELEASE
${ENVIRONMENT_EXTENSION}
)
#set project sources
SET(PROJECT_SOURCES
${CMAKE_CURRENT_LIST_DIR}/GenericBaseForm.h
${CMAKE_CURRENT_LIST_DIR}/GenericBaseForm.cpp
${CMAKE_CURRENT_LIST_DIR}/GenericForm.h
${CMAKE_CURRENT_LIST_DIR}/GenericForm.cpp
${CMAKE_CURRENT_LIST_DIR}/GenericSensorForm.h
${CMAKE_CURRENT_LIST_DIR}/GenericSensorForm.cpp
)
SET(PROJECT_RESOURCES
)
#set project sources
SET(PROJECT_UI
)
# setup project
ADD_LIBRARY(${PROJECT_NAME} STATIC
${PROJECT_SOURCES}
${UI_WRAP}
${MOC_SOURCES}
)
TARGET_LINK_LIBRARIES(
${PROJECT_NAME}
PUBLIC
Qt5::Core
Qt5::Gui
Qt5::Widgets
)
GenerateVSUserFile(
"${ENVIRONMENT_EXTENSION_DEBUG}"
"${ENVIRONMENT_EXTENSION_RELEASE}"
"$(TargetDir)"
"$(TargetDir)"
"$(TargetPath)"
"$(TargetPath)"
""
""
"${PROJECT_NAME}"
)
GenerateVersionInfo(
1
0
0
"${PROJECT_NAME}"
"${PROJECT_NAME}"
"${PROJECT_NAME}.lib"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.rc"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_version.h"
)
# Executables fail to build with Qt 5 in the default configuration
# without -fPIE. We add that here.
set(CMAKE_CXX_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
#Set the target link subsystem
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS")
#set compiler flasgs
SET(COMPILER_FLAGS "${COMPILER_FLAGS} /MP")
SET(COMPILER_FLAGS "${COMPILER_FLAGS} /EHsc")
SET(COMPILER_FLAGS "${COMPILER_FLAGS} /Zc:wchar_t")
SET(COMPILER_FLAGS "${COMPILER_FLAGS} /wd4290")
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${COMPILER_FLAGS}")
SET(PROJECT_NAME_INCLUDES ${CMAKE_CURRENT_LIST_DIR} PARENT_SCOPE)
SET(PROJECT_NAME_PROJECTNAME "${PROJECT_NAME}" PARENT_SCOPE)

C++: How to properly link compiled object using CMake in VSCode

OS
Windows 10
CMake: 3.16.3
Editor
VSCode: 1.48.1
Extensions
CMake Tools: 1.4.1
C/C++ 0.30.0-insiders3
Kit
Visual Studio Community 2019 Release - amd64
Project Repo
https://gitlab.com/NumeralRocket/kepler Removed, insufficient for minimal reproducible example
Tutorial
Introduction to Google Test and CMake
https://www.youtube.com/watch?v=Lp1ifh9TuFI
I'm attempting to build unit tests for one of my personal projects using CMake, and while I wholly admit I am quite new to CMake and a novice at C++, I am stumped on how to resolve this problem. When I go to build my project I get the following Linker error:
[main] Building folder: kepler
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build n:/Unreal_Engine/Magellan/kepler/build-vscode --config Debug --target ALL_BUILD -- /maxcpucount:14
[build] Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Framework
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build]
[build] gmock.vcxproj -> N:\Unreal_Engine\Magellan\kepler\build-vscode\lib\Debug\gmockd.lib
[build] gmock_main.vcxproj -> N:\Unreal_Engine\Magellan\kepler\build-vscode\lib\Debug\gmock_maind.lib
[build] kepler.vcxproj -> N:\Unreal_Engine\Magellan\kepler\build-vscode\Debug\kepler.lib
[build] gtest.vcxproj -> N:\Unreal_Engine\Magellan\kepler\build-vscode\lib\Debug\gtestd.lib
[build] gtest_main.vcxproj -> N:\Unreal_Engine\Magellan\kepler\build-vscode\lib\Debug\gtest_maind.lib
[build] LINK : fatal error LNK1104: cannot open file 'Quaternion.lib' [N:\Unreal_Engine\Magellan\kepler\build-vscode\test\QuaternionTests.vcxproj]
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[build] Build finished with exit code 1
For context, the project is structured as follows:
${ProjectRoot}
├── CMakeLists.txt
├── Quaternion.cpp
├── Quaternion.hpp
├── googletest
└── test
├── CMakeLists.txt
└── QuaternionTest.cpp
${ProjectRoot}/CMakeLists.txt
cmake_minimum_required(VERSION 3.16) # version can be different
set(CMAKE_VERBOSE_MAKEFILE ON)
set(This kepler)
get_filename_component(CODE_ROOT ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
project(${This}) #name of your project
project(${This} C CXX)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
enable_testing()
add_subdirectory(googletest)
add_subdirectory(test)
set(Headers
Quaternion.hpp
)
set(Sources
Quaternion.cpp
)
add_library(${This} STATIC ${Sources} ${Headers})
${ProjectRoot}/Quaternion.cpp
#include <iostream>
#include "Quaternion.hpp"
// Default Constructor
Quaternion::Quaternion() {}
// Specified Value Constructor
Quaternion::Quaternion(double qs, double qi, double qj, double qk) : q0(qs), q1(qi), q2(qj), q3(qk) {}
Quaternion operator + (Quaternion const &quatA, Quaternion const &quatB) // 1) § 5.3
{
Quaternion quatC;
quatC.q0 = quatA.q0 + quatB.q0;
quatC.q1 = quatA.q1 + quatB.q1;
quatC.q2 = quatA.q2 + quatB.q2;
quatC.q3 = quatA.q3 + quatB.q3;
return quatC;
}
Quaternion operator - (Quaternion const &quatA, Quaternion const &quatB) // 1) § 5.3
{
Quaternion quatC;
quatC.q0 = quatA.q0 - quatB.q0;
quatC.q1 = quatA.q1 - quatB.q1;
quatC.q2 = quatA.q2 - quatB.q2;
quatC.q3 = quatA.q3 - quatB.q3;
return quatC;
}
void QuaternionLog(Quaternion quat2log)
{
std::cout << "q0: " << quat2log.q0 << std::endl;
std::cout << "q1: " << quat2log.q1 << std::endl;
std::cout << "q2: " << quat2log.q2 << std::endl;
std::cout << "q3: " << quat2log.q3 << std::endl;
}
int main()
{
Quaternion quat1;
Quaternion quat2(1, 2, 3, 4);
Quaternion quat3 = quat1 + quat2;
Quaternion quat4 = quat1 - quat2;
QuaternionLog(quat1);
QuaternionLog(quat2);
QuaternionLog(quat3);
QuaternionLog(quat4);
}
${ProjectRoot}/Quaternion.hpp
#ifndef QUATERNION_H
#define QUATERNION_H
class Quaternion
{
public:
double q0{ 1.0 };
double q1{ 0.0 };
double q2{ 0.0 };
double q3{ 0.0 };
Quaternion();
Quaternion(double qs, double qi, double qj, double qk);
friend Quaternion operator + (Quaternion const &quatA, Quaternion const &quatB);
friend Quaternion operator - (Quaternion const &quatA, Quaternion const &quatB);
};
#endif /* QUATERNION_H */
${ProjectRoot}/test/CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
set(This QuaternionTests)
set(Sources
QuaternionTest.cpp
)
add_executable(${This} ${Sources})
target_link_libraries(${This} PUBLIC
gtest_main
Quaternion
)
add_test(
NAME ${This}
COMMAND ${This}
)
${ProjectRoot}/test/QuaternionTest.cpp
#include <gtest/gtest.h>
#include "../Quaternion.hpp"
TEST(Quaternion, QuaternionConstructors)
{
Quaternion test_quat_1;
ASSERT_EQ(test_quat_1.q0, 1);
ASSERT_EQ(test_quat_1.q1, 0);
ASSERT_EQ(test_quat_1.q2, 0);
ASSERT_EQ(test_quat_1.q3, 0);
ASSERT_EQ(1,1);
};
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
};
How can I:
Ensure and Inspect that objects are being built appropriately?
Properly instruct CMake such that the linker can find my Quaternion (source code) object?
Any insight would be appreciated.
My mistake was in adding my library incorrectly:
${ProjectRoot}/CMakeLists.txt
cmake_minimum_required(VERSION 3.16) # version can be different
set(CMAKE_VERBOSE_MAKEFILE ON)
set(This kepler)
get_filename_component(CODE_ROOT ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
project(${This}) #name of your project
project(${This} C CXX)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
enable_testing()
add_subdirectory(googletest)
add_subdirectory(test)
set(Headers
Quaternion.hpp
)
set(Sources
Quaternion.cpp
)
add_library(${This} STATIC ${Sources} ${Headers})
I was adding a library named ${THIS} which was "kepler" instead of the expected "Quaternion", so:
add_library(Quaternion STATIC ${Sources} ${Headers})
correctly tells the linker what/where to expect my library
AND
Leaving a main function in Quaternion.cpp, which was removed
Solution Source: vector-of-bool

Cannot Open .png file with CImg on CLion (macOS)

I've tried including libpng16/png.h and #define cimg_use_png, but none of them solved the error. Also, I have main.cpp, lenna.jpg and CImg.h in the same directory.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.6)
project(HelloWorld)
set(CMAKE_CXX_STANDARD 17)
set(SOURCE_FILES main.cpp)
add_executable(HelloWorld ${SOURCE_FILES})
set(YOU_NEED_X11 1)
set(YOU_NEED_PNG 1)
if (${YOU_NEED_PNG} EQUAL 1)
message(STATUS "Looking for libpng...")
find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
target_link_libraries (HelloWorld ${PNG_LIBRARY})
target_compile_definitions(HelloWorld PRIVATE cimg_use_png=1)
endif()
if (${YOU_NEED_X11} EQUAL 1)
message(STATUS "Looking for X11...")
find_package(X11 REQUIRED)
include_directories(${X11_INCLUDE_DIR})
target_link_libraries(HelloWorld ${X11_LIBRARIES})
else()
target_compile_definitions(HelloWorld PRIVATE cimg_display=0)
endif()
main.cpp:
#include <iostream>
#include "CImg.h"
using namespace cimg_library;
int main() {
CImg<unsigned char> img("lenna.png");
int h = img.height();
int w = img.width();
int s = img.spectrum();
std::cout << "h: " << h << " w: " << w << " s: " << s << std::endl;
return 0;
}
The error:
[CImg] *** CImgIOException *** [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed to open file 'lenna.png'.
libc++abi.dylib: terminating with uncaught exception of type cimg_library::CImgIOException: [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed to open file 'lenna.png'.
Process finished with exit code 6
It looks like lenna.png is not being found. Relative paths are relative to the directory containing the executable. That means that if the executable is at cmake-build-debug/HelloWorld and you try to open lenna.png, the file at cmake-build-debug/lenna.png is opened. This means that you should either manually copy lenna.png into cmake-build-debug (I don't recommend this) or ask CMake to do it for you.
Add this to your CMakeLists.txt file.
add_custom_command(
TARGET HelloWorld POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/lenna.png
${CMAKE_BINARY_DIR}/lenna.png
)
This will cause lenna.png to be copied into the same directory as your executable every time the executable is compiled.

Undefined Reference errors in ros to opencv image converter

I am trying to do the ros_wiki tutorial to convert ROS images to OpenCV images, but when I try to compile my catkin workspace I get several pages of errors that all have the following form:
CMakeFiles/image_converter.dir/scripts/image_converter.cpp.o: In function `cv::String::~String()':
image_converter.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
I've googled around a lot and found various similar problems, but those problems were all fixed by updating the CMakeLists.txt file and the package.xml file, which did not work for me.
Here is an example of one such solution - they all center around including
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries( your_target ${OpenCV_LIBS} )
in the cmakelists, but I have those already.
My C++ code:
#include <ros/ros.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <string>
#include <iostream>
const std::string wn = "OCV_window";
class ImageConverter
{
ros::NodeHandle nh_;
image_transport::ImageTransport it_;
image_transport::Subscriber image_sub_;
image_transport::Publisher image_pub_;
public:
ImageConverter()
: it_(nh_)
{
image_sub_ = it_.subscribe("/camera/color/image_raw", 1, &ImageConverter::imageCb, this);
image_pub_ = it_.advertise("/image_editor/output_image", 1);
cv::namedWindow(wn);
}
~ImageConverter()
{
cv::destroyWindow(wn);
}
void imageCb(const sensor_msgs::ImageConstPtr& incoming_message)
{
cv_bridge::CvImagePtr cvi;
try
{
cvi = cv_bridge::toCvCopy(incoming_message, sensor_msgs::image_encodings::RGB8);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("CV_Bridge Exception: %s", e.what());
return;
}
cv::imshow(wn, cvi->image);
cv::waitKey(3);
image_pub_.publish(cvi->toImageMsg());
}
};
int main(int argc, char** argv)
{
ros::init(argc,argv, "Image_Converter");
ImageConverter ic;
ros::spin();
return(0);
}
My cmakelists file:
cmake_minimum_required(VERSION 2.8.3)
project(odom_reporter)
add_compile_options(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
geometry_msgs
nav_msgs
roscpp
rospy
std_msgs
message_generation
image_transport
cv_bridge
sensor_msgs
OpenCV REQUIRED
)
add_service_files(
FILES
HMD.srv
)
catkin_package()
include_directories(
${OpenCV_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
)
add_executable (image_converter scripts/image_converter.cpp)
target_link_libraries (image_converter ${OpenCV_LIBS})
My package.xml file:
<?xml version="1.0"?>
<package format="2">
<name>odom_reporter</name>
<version>0.0.0</version>
<description>The odom_reporter package</description>
<maintainer email="calabrnb#mail.uc.edu">Nate Calabrese</maintainer>
<license>BSD</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>nav_msgs</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>message_generation</build_depend>
<build_depend>image_transport</build_depend>
<build_depend>cv_bridge</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>OpenCV</build_depend>
<build_export_depend>geometry_msgs</build_export_depend>
<build_export_depend>nav_msgs</build_export_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>rospy</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<build_export_depend>message_runtime</build_export_depend>
<build_export_depend>image_transport</build_export_depend>
<build_export_depend>cv_bridge</build_export_depend>
<build_export_depend>sensor_msgs</build_export_depend>
<build_export_depend>OpenCV</build_export_depend>
<exec_depend>geometry_msgs</exec_depend>
<exec_depend>nav_msgs</exec_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend>image_transport</exec_depend>
<exec_depend>cv_bridge</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<exec_depend>OpenCV</exec_depend>
<export>
</export>
</package>
That should work, but there's a problem: find_package() only supports finding one package per call.
You're currently trying to find two packages with it, and not finding the second one, OpenCV:
find_package(catkin REQUIRED COMPONENTS
image_transport
cv_bridge
...
)
find_package(OpenCV REQUIRED)
find_package(<package> [version] [EXACT] [QUIET] [MODULE]
[REQUIRED] [[COMPONENTS] [components...]]
[OPTIONAL_COMPONENTS components...]
[NO_POLICY_SCOPE])