Linking between two workspaces in ROS 2 - c++

I know I should ask in RosAnswers - I did actually but nobody ever answered and I still struggle with this so I thought I should try asking here.
To keep everything neat and clean I have a dev_ws with my packages and a tools_ws with all other packages (vision_opencv, perception_pcl etc.).
Now I´m not sure why but when I try to include header files from packages in tools_ws in my own dev_ws packages colcon is unable to find those headers. So if I try to add #include <pcl_conversions pcl_conversions.h> in my header file the error message will read
/home/test_ws/src/test_pkg/include/CameraAdapter.h:8:10: fatal error:
pcl_conversions/pcl_conversions.h: No such file or directory #include
<pcl_conversions/pcl_conversions.h>
I usually just add <depend>pcl_conversions</depend> in my package.xml and find_package(pcl_conversions REQUIRED) in my CMakeList.txt
The tools_ws is sourced and ros2 is able to find launchfiles etc in there and my python nodes are able to use packages from tools_ws, just using include files in Cpp isn´t working. I´m quite sure the answer is really simple, probably just a line in my CMakeList but I didn´t manage to find anything in the Ros2 Documentation or via googling.
Do you have any idea what I´m doing wrong?

Related

Include OpenCV for Project in C++

I feel like this should be basic, but I can't find anything for it online. I downloaded OpenCV and can't figure out how to have my projects recognize it. When I try to include it with like
#include <opencv2/core/version.hpp>
I get the error:
"No such file or directory"
The only solution I've tried is to add /usr/include/opencv4/ to my PATH. Also, I am running ArchLinux if that is helpful to know.
So I ended up just moving the directory /usr/include/opencv4/opencv2 to /usr/include and that worked. Unless there are any ways to add directories to the list of directories that c++ checks when running the #include, this is the only way I've figured to solve it.
if you have trouble with this
#include <opencv2/core/version.hpp>
You can find more detail information on "Googling".
what I have organized shown below:
try using include "opencv2/core/version.hpp" instead of it.
right-click, then check-the-location
recheck several environment settings:
Additional Include Directories
Linker
Additional Dependencies
PATH
Try changing these three:
PATH=$PATH:/usr/bin
CPATH=$CPATH:/usr/include/opencv4
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64:/usr/lib

*Where* to replace ```sys/time.h``` header dependency in Windows?

I've been trying to install a package on my Windows machine using Git bash. I encounter the error: fatal error C1083: Cannot open include file: 'sys/time.h': No such file or directoryerror', which multiple StackOverflow questions try to address (see here, here2 and here3). There's no shortage of possible answers but no updated/current solutions.
By way, I came across a possible solution, offered by the link below, which suggests to create 3 files, time.h, times.h and times.cpp. The problem is, it's unclear to me where to place these three files - the author suggests to put them in the same "project folder" but this is unclear to me. I created a folder sys with these three files in the same project and tried to compile, to no avail. Is there something simple I'm overlooking?
https://www.codefull.net/2015/12/systime-h-replacement-for-windows/

Using connector c++ to access MYSQL database (How to add a path to my standard search directory)

I am relatively new to programming&C++ and just began learning about MYSQL. I have been searching for a couple of days but couldn't find a solution. I usually use Cygwin&VIM&g++ to write, compile and run codes that I write.
My goal is to retrieve data from MYSQL database that I've set up on my laptop and be able to run a simple algorithm on that data and possibly update the database.
I went into MYSQL's website and went through tutorials and found an example here. I have Boost, Connector, MYSQL server lib downloaded. When I run it, I get an error saying 'connection.h' was not found. I'm sure this is because when I compile it, g++ does not have the location of the library added to the search path that it goes through. The example has something like:
#include <cppconn/conneciton.h>
where these angled brackets means it is going to search (after the current directory) the standard search directory. I am guessing I have to add a new path (the location of where the libraries are) so that the compiler looks at that standard directory and compiles the header.
Through googling I am thinking in g++ I can use -Ldir -I to add a new search path but I don't get how to use it. Can anyone kindly explain/show me (by example) how to get over with this problem? :(
An #include issue would be solved with -I (-L is for a library if it is needed but first you have to get through the compile).
You need to figure out where the headers were installed (likely somewhere under either /usr/include or /usr/local/include/), and then add a -I with that directory, it may also be that you need to install a development package, many *nix distributions split based on runtime-build time distinctions.
And note also with the -I that the package may do something like install to /usr/include/libraryname/libname_version/libname in such a case you would only want to add -I/usr/include/libraryname/libname_version/ and then in your source file have #include

SCons not finding "stdafx.hpp" when using nested directories

I have a C++ project, and I am transitioning from Visual Studio Solutions to SCons for builds, so Linux users can also build my code. This is my first foray into SCons, and it's working very well with simple projects. But, for this project, I have a nested directory structure:
main/
sub1/*.cpp
sub2/*.cpp
sub3/*.cpp
file1.cpp
file2.cpp
And I have the following SConstruct file:
env = Environment()
env['PCHSTOP'] = 'stdafx.hpp'
env['PCH'] = env.PCH('stdafx.cpp')[0]
env.Program('program', [
'file1.cpp',
'file2.cpp',
'sub1/file1.cpp',
'sub2/file1.cpp',
'sub3/file1.cpp'
])
Running scons from the command line causes the following error:
fatal error C1083: Cannot open include file: 'stdafx.hpp': No such file or directory
Obviously, this is an MSVC error. But this should be solvable with Scons, I'm just not sure how..
I Noticed that Visual Studio will copy all the *.obj files to a build directory before linking by default. I think this may be part of the solution, but again, I'm unsure.
What I AM sure of, is this is not the first time someone has come across this problem, but Google didn't turn up anything for me.
PS: Unlike in the example, none of the files have naming conflicts, and could theoretically be moved to a flattened folder structure by SCons without issue.
This looks like you'll have to specify the proper include paths in your Environment via the "CPPPATH" variable...but it's difficult to tell without seeing the full command line. Remember, that all SCons envs are clean initially. So, if you're in the wrong working directory, a simple "#include " doesn't find the header if it's in a different folder.
Have a look at SCons' UserGuide, chap. 14 "Hierarchical Builds", which might give you a few more ideas and insights, or come over to the User mailing list at scons-users#scons.org.

Trouble including NSS header Files

Very recently, I had this idea to start using Mozilla NSS and to learn to use it, so that somewhere in the future, i can use it, or can atleast start contributing to it.
So i went to its Website and cloned it source code into a director "NSS" using mercurial
Then I used
make nss_build_all
instead of
gmake nss_build_all
Note : I don't know, if it makes a difference, gmake is just GNU Make
This make command created a dist folder outside the nss folder. So, Now my NSS folder has 3 folders nss,nspr,dist.
In .bashrc i added a line at the end
export LD_LIBRARY_PATH=/home/ayusun/workspace/NSS/dist/Linux3.5_x86_glibc_PTH_DBG.OBJ/lib
Then i went over to this Sample code, did a copy paste and saved it in my NSS Folder.
And then i tried to compile it, but it failed, stating it couldn't find iostream.h, I went over and changed the location of header files
So
<iostream.h> became <iostream>
"pk11pub.h" became "nss/lib/pk11wrap/pk11pub.h"
"keyhi.h" became "nss/lib/cryptohi/keyhi.h"
"nss.h" became "nss/lib/nss/nss.h"
I tried compiling again but this time error came, that it couldn't find "planera.h"
which is actually present in dist/*.OBJ/include/ which is a link to a file planeras.h in nspr
And so i don't know, how to include these files anymore.
I always have trouble when it comes to include 3rd party header files.
Thanks
This is an old question, but I'll answer it anyway for future reference.
The simplest way is just to use the NSS package for your operating system.
Then you can use things like nss-config --cflags, nss-config --libs, nspr-config --cflags and nspr-config --libs and add that to your CFLAGS and LDFLAGS as appropriate.
For those who do decide to compile their own NSS, I'll give the quick overview.
The NSS headers are in dist/public. Add -I/path/to/dist/public to your compiler command line. The NSPR headers are in dist/Debug/include¹ so add -I/path/to/dist/Debug/include to your comiler command line.
Now you can use #include <nspr/prio.h> and #include <nss/nss.h> and friends.
The NSS code relies on directly uncluding the NSPR headers, so you'll need to add -I/path/to/dist/Debug/include/nspr for it to find things like plarena.h. Or you could do the same and not prefix your includes like I did above. It's up to you.
Now add -L/path/to/dist/Debug/lib and -lnss3 -lnspr4 to your linker command line. You may want to also add -rpath /path/to/dist/Debug/lib for the runtime link path, or copy them to a system directory or use LD_LIBRARY_PATH.
I hope this gets you started.
¹ This actually depends on your operating system and build type. I hope you can figure out the name of the actual Debug directory in your case.