I am making a program on raspberry pi and it uses opencv and mysql. they both compile fine when I compile them separately. but after i combine the 2 files I cannot compile them.
I could compile my opencv part using
g++ $(pkg-config --libs --cflags opencv) cv.cpp -o cv -I/home/pi/git/robidouille/raspicam_cv -L/home/pi/git/robidouille/raspicam_cv -lraspicamcv -L/home/pi/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host
without any problem and compile my mysql part using
g++ -w sql.cpp $(mysql_config --cflags) $(mysql_config --libs)
but after I merge the code and try to compile the merged code using
g++ $(pkg-config --libs --cflags opencv) merged.cpp -o merged $(mysql_config --cflags) $(mysql_config --libs) -I/home/pi/git/robidouille/raspicam_cv -L/home/pi/git/robidouille/raspicam_cv -lraspicamcv -L/home/pi/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host
I get an error saying error: ‘conn’ does not name a type
here is my code for that section
MYSQL *conn;
conn = mysql_init(NULL); //error here
Related
I need to use cv_bridge and transfer the images to vison wx. I am using makefile to link / compile. The problem I have is I don't know where the header files are for the opencv 3.2 libraries. This is on a Jetson Xavier, opencv 3.2 may have been installed by the SDK Manager, or I may have installed it later. Anyway, I just reinstalled it now using the command
sudo apt-get install --reinstall libopencv-core3.2
To identify the compiler and linker flags, I run the the two pkg-config commands
pkg-config --cflags cv_bridge
-I/opt/ros/melodic/include -I/usr/include/opencv -I/opt/ros/melodic/include
pkg-config --libs cv_bridge
-L/opt/ros/melodic/lib -lcv_bridge /usr/lib/aarch64-linux-gnu/libopencv_core.so.3.2.0 /usr/lib/aarch64-linux-gnu/libopencv_imgproc.so.3.2.0 /usr/lib/aarch64-linux-gnu/libopencv_imgcodecs.so.3.2.0 -lrosconsole -lrosconsole_log4cxx -lrosconsole_backend_interface /usr/lib/aarch64-linux-gnu/liblog4cxx.so /usr/lib/aarch64-linux-gnu/libboost_regex.so /usr/lib/aarch64-linux-gnu/libboost_system.so /usr/lib/aarch64-linux-gnu/libboost_thread.so /usr/lib/aarch64-linux-gnu/libboost_chrono.so /usr/lib/aarch64-linux-gnu/libboost_date_time.so /usr/lib/aarch64-linux-gnu/libboost_atomic.so /usr/lib/aarch64-linux-gnu/libpthread.so -lroscpp_serialization -lrostime /usr/lib/aarch64-linux-gnu/libboost_date_time.so /usr/lib/aarch64-linux-gnu/libboost_system.so /usr/lib/aarch64-linux-gnu/libboost_thread.so /usr/lib/aarch64-linux-gnu/libboost_chrono.so /usr/lib/aarch64-linux-gnu/libboost_atomic.so /usr/lib/aarch64-linux-gnu/libpthread.so -lcpp_common /usr/lib/aarch64-linux-gnu/libboost_system.so /usr/lib/aarch64-linux-gnu/libboost_thread.so /usr/lib/aarch64-linux-gnu/libboost_chrono.so /usr/lib/aarch64-linux-gnu/libboost_date_time.so /usr/lib/aarch64-linux-gnu/libboost_atomic.so /usr/lib/aarch64-linux-gnu/libpthread.so /usr/lib/aarch64-linux-gnu/libconsole_bridge.so.0.4
From the above output, there is a opencv core library at
ls /usr/lib/aarch64-linux-gnu/libopencv_core.so.3.2.0
/usr/lib/aarch64-linux-gnu/libopencv_core.so.3.2.0
The problem is I can't find the header files for opencv 3.2. From the output above, the header files should be in directory
-I/usr/include/opencv
In directory /usr/include/opencv, there is a subdirectory
/usr/include/opencv4/opencv2_orig/core/version.hpp
And that contains the version.hpp file which contains these lines showing the version is version is 4.1.1.
file: /usr/include/opencv4/opencv2_orig/core/version.hpp
#define CV_VERSION_MAJOR 4
#define CV_VERSION_MINOR 1
#define CV_VERSION_REVISION 1
So, how can I install the header files for opencv version 3.2, that go with cv_bridge? Also, there may be a ROS package solution to this question, that may be more appropriate since cv_bridge library is in /opt/ros/melodic/lib.
Hmmm I see there's no tag for cv-bridge. I think that means I'm in the wrong blog. Any suggestion where I should post this question?
Opencv 3.2 can be installed using the command below, and the header files are placed in /usr/include/opencv2. I believe what has occurred is opencv4 was installed, and at that time the header files for opencv 3.2 were removed.
sudo apt install libopencv-dev=3.2.0+dfsg-4ubuntu0.1
Here is an example of linking cpp code step_2 with rosbag, cv_bridge, and opencv (3.2). The include -I/opt/ros/melodic/include is not required, it is generated by the rosbag pkg-config command, but is included for clarity, to identify location of cv_bridge header.
g++ step_2.cpp -o step_2 `pkg-config --cflags --libs rosbag` \
-I/opt/ros/melodic/include \
-L/usr/lib/aarch64-linux-gnu/ -lopencv_core -lopencv_highgui \
-L/opt/ros/melodic/lib -lcv_bridge
ref ros perception
I am trying to compile a shared library using static libraries from Boost and OpenCV. Here below the command I am using to compile my library.
g++ -fPIC libsaliency.cpp -shared -o libsaliency.so \
-I/home/poiesi/data/libraries/boost_1_66_0/installed_w_contrib_static/include -I/home/poiesi/data/libraries/opencv-3.4.0/installed_w_contrib_static/include \
-Wl,--whole-archive \
/home/poiesi/data/libraries/boost_1_66_0/installed/lib/libboost_graph.a \
/home/poiesi/data/libraries/boost_1_66_0/installed/lib/libboost_filesystem.a \
/home/poiesi/data/libraries/boost_1_66_0/installed/lib/libboost_system.a \
/home/poiesi/data/libraries/opencv-3.4.0/installed_w_contrib_static/lib/libopencv_core.a \
/home/poiesi/data/libraries/opencv-3.4.0/installed_w_contrib_static/lib/libopencv_highgui.a \
/home/poiesi/data/libraries/opencv-3.4.0/installed_w_contrib_static/lib/libopencv_imgproc.a \
/home/poiesi/data/libraries/opencv-3.4.0/installed_w_contrib_static/lib/libopencv_imgcodecs.a \
/home/poiesi/data/libraries/opencv-3.4.0/installed_w_contrib_static/lib/libopencv_features2d.a \
/home/poiesi/data/libraries/opencv-3.4.0/installed_w_contrib_static/lib/libopencv_video.a \
-Wl,--no-whole-archive
However, I have this error:
usr/bin/ld: /home/poiesi/data/libraries/boost_1_66_0/installed/lib/libboost_graph.a(read_graphviz_new.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/home/poiesi/data/libraries/boost_1_66_0/installed/lib/libboost_graph.a(read_graphviz_new.o): error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:7: recipe for target 'saliency' failed
make: *** [saliency] Error 1
Does this mean I have to recompile Boost using -fPIC command? I checked this online but I haven't found much info about it. This makes me wonder if I am searching for the right thing. Do you have any suggestion?
EDIT: As suggested below by Mike, I recompiled Boost like this:
./b2 cxxflags="-fPIC" link=static install
and I can now compile my .so library.
Does this mean I have to recompile Boost using -fPIC command?
Yes. All code that is linked into a shared library must be Position Independent Code. Object
files within static libraries normally are not, as shared libraries normally
link other shared libraries.
But there is nothing in principle to stop you from building boost static libraries
from -fPIC-compiled object files.
It would be simpler, of course, to link the shared versions of the boost libraries.
With boost 1.72.0, fixed this problem by recompile boost static library with -fPIC.
./bootstrap.sh --prefix=/usr/
sudo ./b2 cxxflags=-fPIC cflags=-fPIC link=static -a
sudo ./b2 install
I am currently try to compile these files using HDF5
I have directly linked and included everything necessary ( I think) but still the compile unable to find the files that is needed
This is my Makefile:
CC = h5cc
FC = h5fc
LD = h5fc
FDEBUG = -std -g -traceback
CFLAGS = -g -O0 -Wall -pedantic
FFLAGS = -g -O0 -Wall -I$(H5DIR)/include -L$(H5DIR)/lib/libhdf5hl_fortran.a
LDFLAGS = -I$(H5DIR)/include -L$(H5DIR)/lib/libhdf5hl_fortran.a
#LDFLAGS = -I$(MKLROOT)/include -L$(MKLROOT) -mkl=sequential
# -opt-block-factor=16 -opt-prefetch=4 \
.SUFFIXES:
.SUFFIXES: .c .f .f90 .F90 .o
OBJS = timing.o \
kinds.o \
rw_matrix.o \
EXE = matmul_omp.exe
all: $(EXE)
$(EXE): $(OBJS) matmul_omp.o
$(LD) $(LDFLAGS) -o $# $^
.f90.o:
-$(RM) -f $*.o $*.mod
$(FC) $(FFLAGS) -c $<
.c.o:
$(CC) $(CFLAGS) -c $<
.PHONEY: clean
clean:
THis is the err:
h5fc -I/curc/tools/x_86_64/rh6/hdf5/1.8.13/szip/2.1/zlib/1.2.8/jpeglib/9a/openmpi/1.8.2/intel/13.0.0/include -L/curc/tools/x_86_64/rh6/hdf5/1.8.13/szip/2.1/zlib/1.2.8/jpeglib/9a/openmpi/1.8.2/intel/13.0.0/lib/libhdf5hl_fortran.a -o matmul_omp.exe timing.o matmul_omp.o
gfortran: /usr/lib64/libhdf5hl_fortran.a: No such file or directory
gfortran: /usr/lib64/libhdf5_hl.a: No such file or directory
gfortran: /usr/lib64/libhdf5_fortran.a: No such file or directory
gfortran: /usr/lib64/libhdf5.a: No such file or directory
As you can see that I directly link libhdf5hl_fortran.a. but i dont know why the error is giving a different directory /usr/lib64/
I think you have a couple of things wrong here.
If you are using h5fc then you shouldn't need to add all the include and lib paths. That is the whole point of the helper applications.
You are adding the paths that have Intel, yet your h5fc has a GNU (gfortran) error.
The gfortran build of HDF5 looks as if it does not have the fortran bindings built.
I would suggest trying the following. Using the full paths (as you have done) but call ifort instead of h5fc:
ifort -I/curc/tools/x_86_64/rh6/hdf5/1.8.13/szip/2.1/zlib/1.2.8/jpeglib/9a/openmpi/1.8.2/intel/13.0.0/include \
-L/curc/tools/x_86_64/rh6/hdf5/1.8.13/szip/2.1/zlib/1.2.8/jpeglib/9a/openmpi/1.8.2/intel/13.0.0/lib/libhdf5hl_fortran.a \
-o matmul_omp.exe timing.o matmul_omp.o
I'm trying to compile simple OpenCV code on the BeagleBoard XM, running Ångström Linux.
I know my way in OpenCV, but only under Windows and Visual Studio. I'm fairly with non-Microsoft OSes.
I think I've installed OpenCV on the BeagleBoard (opkg install opencv, right?), and I've transferred my code, which for now look like this:
#include <opencv2/opencv.h>
int main()
{
cv::Mat img(100, 100, CV_8U);
cv::imshow("Hello world", img);
cv::waitkey();
return 0;
}
How can I compile this code under the BeagleBoard? How can I tell it where the .so files are? Where are the OpenCV .so files?
Have a look at ECE597 OpenCV on the BeagleBoard for installation instructions.
If you have installed it properly, then open a terminal window and browse to the folder where you have put the code. Once there, use the following command to compile the code in file "main.cpp"
g++ main.cpp -o out `pkg-config --cflags --libs opencv`
After the code is compiled, use the following command to execute it.
./out
Also look at the answers to Stack Overflow question How to install OpenCV on Ångström Linux?.
export LD_LIBRARY_PATH=/usr/local/lib
gcc `pkg-config --cflags opencv` -g -o NameOfProgram main.cpp `pkg-config --libs opencv`
Probably these commands should the work. Just don't forget to change the cpp filename if needed. See this.
I'm trying a tutorial on glib which uses GIOChannel. I'm using Ubuntu 11.04 (Natty Narwhal) with glib-2.30.2 (gtk+-3.2.3) and C code.
The code is from here:
http://library.developer.nokia.com/index.jsp?topic=/GUID-E35887BB-7E58-438C-AA27-97B2CDE7E069/GUID-817C43E8-9169-4750-818B-B431D138D71A.html
The program runs but I the contents of my source test file is not copied to the destination file. I'm not receiving any error or warning messages. The program just does nothing. What's wrong here?
Works now, I changed the line:
g_print("usage:<cp SOURCE> <DESTINATION>\n");
To:
g_print("usage: %s <SOURCE> <DESTINATION>\n", argv[0]);
Then compiled it using:
gcc -Wall $(pkg-config --cflags gio-2.0) -c io.c
gcc -Wall $(pkg-config --libs gio-20) -o io io.o
Run the program using: ./io io.c new_io.c