Error with cmake conan and liblogicalaccess - c++

I have installed the 2.2.1 version of the liblogicalaccess library on Kubuntu 18.04 with CMake 3.17.1 and Conan 1.25.0.
I tried to follow the C++ howto of the liblogicalaccess library and on the second line of code, when running the program it gives the following error:
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_M_construct null not valid
./run.sh: line 9: 6781 Aborted (core dumped) bin/./github_console
main.cpp
// my first program in C++
#include <iostream>
#include <logicalaccess/dynlibrary/librarymanager.hpp>
#include <logicalaccess/readerproviders/readerconfiguration.hpp>
#include <logicalaccess/cards/chip.hpp>
int main()
{
std::cout << "Hello World!\n";
// Reader configuration object to store reader provider and reader unit selection.
std::shared_ptr<logicalaccess::ReaderConfiguration> readerConfig(new logicalaccess::ReaderConfiguration());
// Set PCSC ReaderProvider by calling the Library Manager which will load the function from the corresponding plug-in
readerConfig->setReaderProvider(logicalaccess::LibraryManager::getInstance()->getReaderProvider("PCSC"));
}
The first line of code starting with std::shared_ptr.. just runs fine, so might this be faulty code within the library or could this be a version/compatility fault. The second line calling the getReaderProvider somehow causes the error. I have no idea where to look for the fix of this error. Came from this problem originally. That was fixed but still stuck at the same code. I did some random troubelshooting but no luck. Any advice?
EDIT:
My CmakeLists.txt is:
project(test)
cmake_minimum_required(VERSION 3.16)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
set(CMAKE_CXX_FLAGS "-I /usr/include/PCSC")
add_executable(test main.cpp)
target_link_libraries(test PUBLIC CONAN_PKG::LogicalAccess)
conanfile.txt:
[requires]
LogicalAccess/2.2.1
[generators]
cmake
[imports]
lib, * -> lib
And to build i just run cmake --build . in the project_folder/build.

Related

How to control a robot from Gazebo using ROS2 Foxy?

I'm utterly confused by the Gazebo/Ignition simulation programs. I'm currently using ROS2 Foxy with Ubuntu 20.04 and looking forward to controlling an UAV modeled in Gazebo via ROS2. However I'm completely lost even though there's "documentation" (which I've found it to be really mixed up between all the different versions of ROS).
What I've done so far is trying to run this script:
#include <iostream>
#include <ignition/msgs.hh>
int main()
{
ignition::msgs::Vector3d point1;
point1.set_x(1);
point1.set_y(3);
point1.set_z(5);
ignition::msgs::Vector3d point2;
point2.set_x(2);
point2.set_y(4);
point2.set_z(6);
std::cout << "Point1:\n" << point1.DebugString() << std::endl;
std::cout << "Point2:\n" << point2.DebugString() << std::endl;
return 0;
}
However I get the message that the build fails since there is no ignition directory even though I have installed it.
I'd appreciate any help in this matter since I feel I'm completely lost with installations and the CMakeLists.txt file.
Gustavo,
with this CMakeLists.txt you can compile your code:
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
find_package(gz-cmake3 REQUIRED)
project(message-example)
gz_find_package(gz-msgs9 REQUIRED)
set(GZ_MSGS_VER ${gz-msgs9_VERSION_MAJOR})
add_executable(message-example main.cpp)
set_property(TARGET message-example PROPERTY CXX_STANDARD 17)
target_link_libraries(message-example
PRIVATE gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER})
then execute
mkdir build
cd build
cmake ..
./message-example
I don't know which Gazebo version are you using but the version for gz-msgs might be different:
Garden - msgs9
Fortress - msgs8
Citadel - msgs5
You can find here some examples related with Gazebo or if you are going to use Gazebo and ROS you should review this other repository ros_gz.

How can I fix CLion problem with filesystem inlcude?

I use a CLion as my IDE. I create project with C++17 standard.
I have a code fragment below:
#include <filesystem>
namespace fs = std::filesystem;
std::vector<std::string> getFilesArray() {
auto dir = ".";
std::vector<std::string> filesList;
for (auto item : fs::recursive_directory_iterator(dir))
{
if (!fs::is_regular_file(item.path()) || item.path().extension() != ".cpp" && item.path().extension() != ".h" && item.path().extension() != ".hpp")
continue;
filesList.push_back(item.path().string());
}
return filesList;
}
When I try to compile project I have a lot of errors like:
C:/PROGRA~2/MINGW-~1/I686-8~1.0-P/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)':
C:/PROGRA~2/MINGW-~1/I686-8~1.0-P/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:47: error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')
|| (__p.has_root_name() && __p.root_name() != root_name()))
My Cmake file is:
cmake_minimum_required(VERSION 3.15)
project(FinalParser)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "-std=c++17 -lc++fs")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(FinalParser main.cpp Parse/Parser.cpp Parse/Parser.cpp Parse/Parser.h files.h Graph/Parser.cpp Graph/Parser.h)
target_link_libraries(FinalParser stdc++fs)
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/Users/user/Desktop/boost_1_71_0")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/Users/user/Desktop/boost_1_71_0/libs")
FIND_PACKAGE(Boost)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()
How can I fix it?
So, I am going to give you the full proof solution for this similar error which also comes when someone tries to use the STL header file which is #include<bits/stdc++.h>
So, this error is occurring because you are currently using the GCC version 8.2.0 which is the default on the MinGW website. To solve this problem you need to update to GCC 10.2.0
Following are the steps you need to follow:-
Download and install the Msys2 from https://www.msys2.org/
Run or launch this and type pacman -Syu and hit enter then it will ask you to continue by typing Y/N just type enter without pressing Y/n.
Close this and again launch msys2 and again type the same command until it shows nothing to do with or nothing to update.
For doing the same I am also sharing a link of the youtube video.
https://www.youtube.com/watch?v=aXF4A5UeSeM&
5. For checking that you have successfully installed GCC 10.2.0 just open cmd and type GCC --version and hit enter if it is showing 10.2.0 hurray u did it, wait this is not the end.
6. Now uninstall Clion or any IDE which you are using.
7. Before reinstalling it you need to delete some of the remaining Jetbrains dump files which are showing in your program files folder (name Jetbrains) Delete that folder and Reinstall it.
8. Now select Msys2/MingW-64, not the previous one which you have in your system already (normal MinGW) while installing it.
9. Now You can go to your add or remove program section and can delete that waste normal MinGW-64, not the msys2 (don't delete msys2) only delete ming64 the previous one.
10. Now you can enjoy running that sexy stl library without having any error.
Still, if you have any problem doing these steps just ask me in a comment.

Pretty printing in Eclipse C++ works for some projects and doesn't for others

I have enabled pretty printing for Eclipse-CDT. This is my previous question: Enable pretty printing in Eclipse C++
I have done all the steps as mentioned in my previous question. I realized that pretty printing does work for a simple test program but doesn't work on my projects. Hence, I am opening a new question as this seems to be project-specific settings.
This is my setup:
Eclipse Version: 2018-09 (4.9.0)
gdb 7.11.1
Xubuntu 16.04
gcc 7.4.0
g++ 7.4.0
I have a simple test.cpp
#include <map>
#include<vector>
int main() {
std::map<char, int> first;
first['a'] = 10;
first['b'] = 20;
std::vector<int> a{1,2,3,4,5};
}
I import this into Eclipse using New > Makefile Project with Existing Code, compile it in terminal:
g++ -g -o test test.cpp
I then debug this program in Eclipse and got this:
Name : first
Details:std::map with 1 element = {[97 'a'] = 10}
Default:{...}
Decimal:{...}
Hex:{...}
Binary:{...}
Octal:{...}
So pretty printing works in Eclipse-CDT for this simple test case. I am assuming whatever settings in Eclipse > Windows > Preferences are set up fine.
For my other two projects (one of which is using https://github.com/Svalorzen/AI-Toolbox), I paste the code snippet in test.cpp into the main.cpp, compile it using make with project-specific CMakeLists in Eclipse, debug it and got this:
For one of the projects:
Name : first
Details:{_M_t = {_M_impl = {<No data fields>}}}
Default:{...}
Decimal:{...}
Hex:{...}
Binary:{...}
Octal:{...}
For the other project:
Multiple errors reported.
1) Failed to execute MI command:
-var-create - * first
Error message from debugger back end:
Null value returned for children
2) Unable to create variable object
3) Failed to execute MI command:
-var-create - * first
Error message from debugger back end:
Null value returned for children
I have checked the Debug Configuration > Debugger for all 3 cases and the settings are the same. Does anyone have any idea why am I getting these errors?
I am guessing that I might need to modify the CMakeLists but I do not have sufficient knowledge to figure this out. This is the snippet of my CMakeLists for both projects:
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
The full CMakeLists is here https://github.com/Svalorzen/AI-Toolbox/blob/master/CMakeLists.txt
So after fiddling with CMakeLists, I figured out the offending line that disables pretty printing:
set_target_properties(lib PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${LTO_SUPPORTED})
Removing this line will make pretty printing work. I changed it to this instead and build in debug mode.
IF(CMAKE_BUILD_TYPE MATCHES Release)
set_target_properties(lib PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${LTO_SUPPORTED})
ENDIF(CMAKE_BUILD_TYPE MATCHES Release)

CMakeLists Issue: bad_alloc error when calling resize() on thrust::device_vector

I am new to thrust library and trying to use it in my project. Here is a very simple code example. It can be compiled without any problem. However, when I try to run it, it gives me an error:
terminate called after throwing an instance of 'thrust::system::detail::bad_alloc'
what(): std::bad_alloc: unknown error
along with a warning:
nvlink warning : SM Arch ('sm_20') not found in ...
The project can be reproduced by using the following two files.
test.cpp
#include <thrust/device_vector.h>
int main(){
thrust::device_vector<int> x;
x.resize(10);
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.9)
project(test_project)
find_package(CUDA QUIET REQUIRED)
list(APPEND CUDA_NVCC_FLAGS "-std=c++11;-arch=compute_52")
set(CUDA_SEPARABLE_COMPILATION ON)
cuda_add_executable("cuda_test" "test.cu")
After some testing, it is obvious that if the line "set(CUDA_SEPARABLE_COMPILATION ON)" is removed, the program runs without problem. But I really need separable compilation activated for my project.
Any help or hint would be appreciated.
UPDATE:
Requested by #RobertCrovella, here are some more infos.
The CUDA version is 7.5, which is newly installed on UBUNTU 14.04 with GTX980. I did not update the Thrust library after that.
The following is the actual command generated by cmake by using "make VERBOSE=1".
CMake script with separable compilation
CMake script without separable compilation
UPDATE 2:
The same error is confirmed by #merelyMark. Since both the code and the CMakeLists file are extremely simple, is it possible that this is a bug in Thrust / CUDA ? [EDIT] No.
UPDATE 3:
Pointed out by #RobertCrovella, thrust library is working fine with proper cmake comands. Now the question: how can I generate those commands using CMakeLists?
Apologies in advance, I don't have enough points to add a comment, but I can confirm the behavior on my rig. This compiles properly on my machine with an E5-1650 v3 and a Quadro M4000 with CUDA 7.5 and Ubuntu 14.04.3. I get one warning error:
nvlink warning : SM Arch ('sm_20') not found in ...
I can confirm the behavior when I run it:
./cuda_test
terminate called after throwing an instance of 'thrust::system::detail::bad_alloc'
what(): std::bad_alloc: unknown error
Aborted (core dumped)
I agree with #RobertCrovella, I'm not really sure what you're trying to accomplish here.
Here's my VERBOSE output for separable compilation.
Here's my VERBOSE output without separable compilation.

How to get std::cout to show in eclipse IDE console when using boost.test?

As the question says, I am having trouble seeing std::out statements in the eclipse console when using the "c/c++ unit" run configuration with boost.test.
Here is a simple example describing the issue.
quickEclipse_stdout.cpp:
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "I see this in the eclipse console!\n";
std::cout << "I also see this in the terminal!\n";
return(0);
}
quickEclipse_stdout_test.cpp:
#include <iostream>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(quickTest_stdout)
BOOST_AUTO_TEST_CASE(bla)
{
std::cout << "I cannot see this in the eclipse console" << std::endl;
std::cout << "but I can see it when run outside eclipse in terminal" << std::endl;
BOOST_CHECK_MESSAGE(true, "of course I see this in eclipse c/c++ test log");
}
BOOST_AUTO_TEST_SUITE_END()
I used cmake to generate project files for eclipse.
CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(quickTest CXX)
FIND_PACKAGE(Boost COMPONENTS program_options filesystem regex unit_test_framework)
IF (Boost_FOUND)
MESSAGE("Boost found!!!")
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()
#main output to console works
ADD_EXECUTABLE(quickEclipse_stdout, quickEclipse_stdout.cpp)
#boost.test output to console doesnt work
ADD_EXECUTABLE(quickEclipse_stdout_test UTDriver.cpp quickEclipse_stdout_test.cpp)
TARGET_LINK_LIBRARIES(quickEclipse_stdout_test ${Boost_LIBRARIES})
UTDriver.cpp:
#define BOOST_TEST_MODULE myQuickEclipseUT
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
To generate the eclipse project I run the following command:
cmake -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_ECLIPSE_VERSION=4.3 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER_ARG1=-std=c++11 ~/mySrcDir
I open the project in eclipse and enter c++ perspective
I then build the executables by double-clicking on make targets (quickEclipse_stdout, quickEclipse_stdout_test)
I goto run configurations and create "c/c++ application" for quickEclipse_stdout.
I goto run configurations and create "c/c++ unit" for quickEclipse-stdout_test and select boost as the test runner.
I run quickEclipse_stdout and see the output in eclipse console.
I run quickEclipse_stdout_test and the eclipse console is empty. I see the message in the c/c++ unit messages tab.
I can see the std::out on both if I run the executables in a terminal outside eclipse.
How can I get the std::out to show in the eclipse console when running the quickEclipse_stdout_test?
I am on Linux CentOS 6.5.
Eclipse Standard/SDK
Version: Kepler Service Release 1
Build id: 20130919-0819
Eclipse C/C++ Development Tools
Version: 8.2.1.201309180223
Im sure based on your description its redirecting stdout to its own window for testing purposes
I am exactly in your situation and I think it is a missing feature of the C/C++ unit test plugin in Eclipse.
The plugin requires the whole test output in xml format (--output_format=XML) which puts the stdout messages in the node of the xml output. The output will be directly parsed by the plugin and the information is organized in the according view. The plugin misses the option to show the stdout messages. I could simply have a further icon beside error, warning, information to show the stdout messages.
I have opened an issue for this on github: https://github.com/xgsa/cdt-tests-runner/issues/14 but the project it not actively maintained the last years...