I'm trying to compile roscpp without using the rest of ROS (I only need to subscribe to a node but the one that own that uses an old version of ROS and I couldn't integrate my program with his due to compilation troubles). I downloaded the source code from git (https://github.com/ros/ros_comm) and now I need to compile it, but Cmake throw me errors:
INFOBuilding GTest from source.
TODO: implement add_roslaunch_check() in rostest-extras.cmake.
CMake Error at CMakeLists.txt:8 (catkin_package_xml):
Unknown CMake command "catkin_package_xml".
How can I build it? I'm calling cmake CMakeList.txt, but it doesn't work.
Use this command line to compile your code directly with g++:
g++ yourtest.cpp -o yourtest -I/opt/ros/indigo/include -L/opt/ros/indigo/lib \
-Wl,-rpath,/opt/ros/indigo/lib -lroscpp -lrosconsole -lrostime \
-lroscpp_serialization -lboost_system -lboost_thread -pthread -lactionlib
Where yourtest.cpp is your c++ file that has some ros code.
If you are using a ros version different of the indigo replace de indigo string by the string of your version.
I suggest you to use rosinstall_generator to compile the package you want, such as roscpp. Here are the steps:
Download the package and its dependencies:
rosinstall_generator roscpp --rosdistro <ROS_Distro that you use> --deps > roscpp_ros.rosinstall
wstool init src roscpp_ros.rosinstall -j8
rosdep install --from-path src -i -y
Then compile it:
src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release
The compiled packages will be in the folder install_isolated (at the same level as the folder src)
Related
I'm on Arch Linux, and I have a C++ SDL2 program, contained in single main.cpp file, and I compile it for Linux with such command:
g++ main.cpp -lSDL2 -lSDL2_image
Now I wanna compile it for windows. Any advice on what should I do?
I suggest my own tool, quasi-msys2, which lets you reuse the precompiled SDL2 for MinGW provided by MSYS2 (and more).
Install Clang, LLD, make, wget, tar, zstd, gpg.
git clone https://github.com/HolyBlackCat/quasi-msys2
cd quasi-msys2/
make install _gcc _SDL2 _SDL2_image
env/shell.sh
win-clang++ main.cpp `pkg-config --cflags --libs sdl2 SDL2_image`
This should produce a.exe, which you can test using wine a.exe (or just ./a.exe, after running env/shell.sh).
How to do this manually:
For completeness, SDL2 itself distributes precompiled binaries for MinGW, meaning the manual setup is not hard. Any tutorial for MinGW should work.
Install MinGW from your package manager.
Download and unpack SDL2-devel-??-mingw.zip and SDL2_image-devel-??-mingw.zip.
Specify the paths to the directories with .a files using -L... and to .h files using -I.... Add -lmingw32 -lmingw32 -mwindows -lSDL2main -lSDL2 -lSDL2_image to the linker flags.
Follow this troubleshooting guide if you get stuck.
I'd go for cmake really.. SDL2 ships with a CMakeLists.txt and it's as simple as running this from your build folder.
cmake.exe ..
cmake.exe --build .
EDIT: if you want to cross-compile, you need MinGW and the addition of the mingw flags to the cmake generator
cmake \
-D CMAKE_C_COMPILER=/path/to/wingw/gcc \
-D CMAKE_CXX_COMPILER=/path/to/mingw/g++ \
-G "MinGW Makefiles" ..
Im currently trying to compile a cpp program with gcc that uses SDL2 library, and im using Ubuntu 20.04 LTS. Here is my folder structure
project
-out
-SDL2
-src
-main.cpp
Excluding the library i have uploaded everything to this repo https://github.com/probottpric/libtest if it gives a better understanding.
To install SDL2, I installed source code and ran ./configure and make all. I dont want to run make install which installs it on /usr/*. I want the library to be on the local folder.
To compile program im using this command
gcc -o ./out/main ./src/main.cpp -ISDL2 -lSDL2 -lSDL2main -lm -std=c++11
But It shows library not found error. What am i doing wrong ?
So I follow the official tutorial for the installation : https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/
Neverless, I can't use the produced libraries as static.
So I managed to compile the C version of the driver as described, I've enabled the flag --enable-static=yes with the ./configure before doing make && sudo make install and I got the libmongoc-1.0.a and the libbson-1.0.a which are static. So this far, everything it's alright.
Then I have done the cxx version of the driver, except that there is no configuration file as in the C version. So I've juste done a
cmake -DCMAKE_BUILD_TYPE=Release -DBSONCXX_POLY_USE_BOOST=1 -DCMAKE_INSTALL_PREFIX=/usr/local
from the build folder, followed by a make && sudo make install
So I got the libmongocxx.a and the libbsoncxx.a, but when I try to compile with them, I can't run the binary because I got the following error :
error while loading shared libraries: libmongocxx.so._noabi: cannot open shared object file: No such file or directory
So I understand that is because there is some symbols missing and then I need to use the shared library to run the binary but I don't want this to happend, I want the symbols within the binary that I can run it without any LD_PRELOAD.
Any suggestions ?
I had the same issue in an Ubuntu 16.04 and I run a apt-get update & apt-get upgrade and the problem was solved.
It seems that there were some update to the compiler and some libraries that prevent some test from reaching the shared libraries.
I have a similar question, and solved, now I compiled and run my binary with static libs successfully.
I write my build script using newlisp, but the static link options are very helpful, I paste it here.
c++ /to/your/path/site/code/back_end/builder/object/files1.cc.o ... /to/your/path/site/code/back_end/builder/object/files10.cc.o -o bin/site -static-libgcc -static-libstdc++ -L/usr/lib -lpthread -l:libmongocxx.a -l:libbsoncxx.a -l:libmongoc-1.0.a -l:libbson-1.0.a -lrt -lssl -lcrypto -lsasl2 -l:libboost_log.a -l:libboost_log_setup.a -l:libboost_system.a -l:libboost_thread.a -l:libboost_filesystem.a -lcppcms -lbooster -lcurl -ljsoncpp
Here's the complete log:
/tmp/ccCvErNZ.o: In function `YAML::detail::node& YAML::detail::node_data::get<std::string>(std::string const&, std::shared_ptr<YAML::detail::memory_holder>)':
cricket.cpp:(.text._ZN4YAML6detail9node_data3getISsEERNS0_4nodeERKT_St10shared_ptrINS0_13memory_holderEE[_ZN4YAML6detail9node_data3getISsEERNS0_4nodeERKT_St10shared_ptrINS0_13memory_holderEE]+0x94): undefined reference to `YAML::detail::node_data::convert_to_map(std::shared_ptr<YAML::detail::memory_holder>)'
collect2: error: ld returned 1 exit status
The code I'm trying to compile is simple
#include <iostream>
#include <yaml-cpp/yaml.h>
using namespace std;
int main() {
YAML::Node test = YAML::LoadFile("test.yaml");
if (test["date"]) {
cout << "HELLO";
}
return 0;
}
The YAML I'm using is the example from http://www.yaml.org/start.html
If I just try to load the YAML, it loads fine. But if I try to access any data I get the same error. So it's not a linking problem.
EDIT: I can do things like cout << test and cout << test.type() and other functions. I think the problem is in using a string based map for accessing internal nodes.
It seems that you are not properly linking the yaml-cpp library. Add the argument -lyaml-cpp when compiling. For example:
g++ -I/usr/local/include -L/usr/local/lib -lyaml-cpp -o test main.cpp
EDIT
Another option is to include this cmake to your CMakeLists.txt:
# attempt to find static library first if this is set
if(YAMLCPP_STATIC_LIBRARY)
set(YAMLCPP_STATIC libyaml-cpp.a)
endif()
# find the yaml-cpp include directory
find_path(YAMLCPP_INCLUDE_DIR yaml-cpp/yaml.h
PATH_SUFFIXES include
PATHS
~/Library/Frameworks/yaml-cpp/include/
/Library/Frameworks/yaml-cpp/include/
/usr/local/include/
/usr/include/
/sw/yaml-cpp/ # Fink
/opt/local/yaml-cpp/ # DarwinPorts
/opt/csw/yaml-cpp/ # Blastwave
/opt/yaml-cpp/
${YAMLCPP_DIR}/include/)
# find the yaml-cpp library
find_library(YAMLCPP_LIBRARY
NAMES ${YAMLCPP_STATIC} yaml-cpp
PATH_SUFFIXES lib64 lib
PATHS ~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw
/opt/local
/opt/csw
/opt
${YAMLCPP_DIR}/lib)
# handle the QUIETLY and REQUIRED arguments and set YAMLCPP_FOUND to TRUE if all listed variables are TRUE
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(YAMLCPP DEFAULT_MSG YAMLCPP_INCLUDE_DIR YAMLCPP_LIBRARY)
mark_as_advanced(YAMLCPP_INCLUDE_DIR YAMLCPP_LIBRARY)
I experienced something similar to this when trying to compile OpenXcom on a Debian system. It turned out that I was using a mix of testing and stable packages, the yaml package was from stable, and the combination somehow made linking fail if there were more than just a few initial functions.
If that is what you're experiencing (and you're using Debian too), try compiling a source package from stable with
apt-get --build source libyaml-cpp0.5/stable
This command will build .deb packages for libyaml, and you can then insert them with dpkg like this:
dpkg -i libyaml-cpp0.5*.deb
as root.
Compiling libyaml from source will make it link to the testing libraries you already have, instead of expecting stable libraries, and so should solve the problem above. It did for me, at least.
Even if you don't use Debian, compiling yaml-cpp from source (e.g. a tarball) might work for similar reasons.
Make sure these two files exist:
/usr/local/lib/libyaml-cpp.a
/usr/local/include/yaml-cpp/yaml.h
My CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 3.4)
FIND_PACKAGE(yaml-cpp REQUIRED)
ADD_EXECUTABLE(yaml_cpp_test yaml_cpp_test.cpp)
TARGET_LINK_LIBRARIES(yaml_cpp_test yaml-cpp)
The content of yaml_cpp_test.cpp is same as mentioned in the question.
I try to reappear the problem on vps (Ubuntu 14.04.1 LTS)
wget -c https://github.com/jbeder/yaml-cpp/archive/release-0.5.1.tar.gz
tar xvf release-0.5.1.tar.gz yaml-cpp-release-0.5.1/
cd yaml-cpp-release-0.5.1/
sudo apt-get install cmake
sudo apt-get install libboost-dev
cmake .
make
make install
after that, yaml-cpp install to /usr/local/lib and /usr/local/include
files in my working directory:
fqlgy#li407-86:~/yaml-cpp$ ll
total 12
-rw-r--r-- 1 fqlgy fqlgy 162 May 8 03:29 CMakeLists.txt
-rw-r--r-- 1 fqlgy fqlgy 10 May 8 03:11 test.yaml
-rw-r--r-- 1 fqlgy fqlgy 240 May 8 03:11 yaml_cpp_test.cpp
As i tried to run "cmake .", there is some error, so i delete the line CMakeFiles/CMakeOutput.log, the content of CMakeLists.txt is :
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
ADD_EXECUTABLE(yaml_cpp_test yaml_cpp_test.cpp)
TARGET_LINK_LIBRARIES(yaml_cpp_test yaml-cpp)
The following output is as expected:
fqlgy#li407-86:~/yaml-cpp$ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fqlgy/yaml-cpp
fqlgy#li407-86:~/yaml-cpp$ make
Scanning dependencies of target yaml_cpp_test
[100%] Building CXX object CMakeFiles/yaml_cpp_test.dir/yaml_cpp_test.cpp.o
Linking CXX executable yaml_cpp_test
[100%] Built target yaml_cpp_test
fqlgy#li407-86:~/yaml-cpp$ ./yaml_cpp_test
HELLO
I confirm that certain versions of yaml-cpp library contain this issue (and it is not about improper linking).
It is rather dirty, but I've resolved it by defining empty functions in my code, it looks like
YAML::BadConversion::~BadConversion()
{
}
void YAML::detail::node_data::convert_to_map(std::shared_ptr<YAML::detail::memory_holder>)
{
}
The approach is not perfect (e.g. because it causes duplicates if another library version is used).
In my case, I run the exact same code on two computer which only give error on one of them and that almost make me crazy. This is not a compilation error, linking error or something, I think the code is dirty or something else.
I tried all option:
regular building from source and installing using cmake .. => make => make install
same as 1, with CC=$(which gcc) CXX=$(which g++) cmake -DBUILD_SHARED_LIBS=ON ..
uninstalling the default package from apt (i use ubuntu 16.04)
all failed, until I find Ilya Golshtein's answer, then in my code which will use yaml-cpp I added this code jsut before YAML::LoadFIle Line
YAML::BadConversion::~BadConversion()
{
}
void YAML::detail::node_data::convert_to_map(std::shared_ptr<YAML::detail::memory_holder>)
{
}
This is the only solution that worked
I'm late to the party here and have no idea what I'm doing but for those of you on Windows, make sure your IDE likes your mingw-g++. Mine auto-defaulted to strawberry perl (?) and when I changed it to mingw-g++ everything started working. I suppose it has something to do with the versioning?
It bothered me, too. I met it when version of yaml-cpp was "0.7.0". I solved it by using "0.6.0" instead.
I have c and c++ project, and i would like to check for dead function (function that could not be called), for that i want to build a call graph and see which could not be accessed from the written code.
for that i want to use clang with the flag "-S -emit-llvm" so i could creat a dot file.
im using autoconf to compile the project and the autoconfig dont recognize the file that has been compiled as an executable.
tried using this line :
./configure --enable-debug --prefix=/opt/ibutils CC=clang CXX=clang++ CXXFLAGS="-S -emit-llvm"
and this
./configure --enable-debug --prefix=/opt/ibutils CC=clang CXX=clang++ CXXFLAGS="-S -emit-llvm"
LD="llvm-link"
does anyone know the reason? have a suggestions what could i do?
thanks