open62541: Error when building PubSub example - gcc

Currently, I am trying to build the PubSub example of the open62541 implementation. I have already gone through the documentation on how to build the examples a several times but I cannot figure it out.
I have tried to compile the PubSub tutorial examples. This includes the tutorial_pubsub_publish.c and the tutorial_pubsub_subscribe.c files. After I cloned the repository, I built the library as followed:
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -
DUA_ENABLE_AMALGAMATION=ON -DUA_ENABLE_PUBSUB=ON ..
make
First I compiled the publish example which worked:
gcc -std=c99 -o PubSub_Publish_Example open62541.c tutorial_pubsub_publish.c
Then, I tried to compile the subscribe example in the same way like this:
gcc -std=c99 -o PubSub_Publish_Example open62541.c tutorial_pubsub_subscribe.c
This generated lots of errors - all saying "No such file or directory(first error was for the #include "ua_architecture_base.h") Then I tried to compile it with the ua_architecture_base.h and get other missing file or directory error and so on...
I also tried to compile the whole include folder of the open62541, but I also get "No such file or directory" errors:
gcc -std=c99 -I /home/theresa/Desktop/open62541/include -o PubSub_Subscribe_Example open62541.c tutorial_pubsub_subscribe.c
I also noticed that of all examples provided by the open62541 master, the tutorial_pubsub_subscribe.c file is the only example which does NOT include
the open62541.h folder. Instead it includes a few other header files:
#include "ua_pubsub_networkmessage.h"
#include "ua_log_stdout.h"
#include "ua_server.h"
#include "ua_config_default.h"
#include "ua_pubsub.h"
#include "ua_network_pubsub_udp.h"
#ifdef UA_ENABLE_PUBSUB_ETH_UADP
#include "ua_network_pubsub_ethernet.h"
#endif
#include "src_generated/ua_types_generated.h"
#include <stdio.h>
#include <signal.h>
So how can I compile and run the tutorial_pubsub_subscribe.c example and why does the subscriber example not include the open62541 header file?

I had success following the instructions "Building with CMake for Windows".
Using cmake-gui I selected the (advanced) features: UA_BUILD_EXAMPLES, UA_ENABLE_PUBSUB, UA_ENABLE_PUBSUB_INFORMATIONMODEL, UA_ENABLE_PUBSUB_INFORMATIONMODEL_METHODS, and UA_NAMESPACE_ZERO = FULL

Related

How to build tests using boost.test on mingw64?

I'm trying to write some code using the boost libraries on windows 10. To build the application I have chosen mingw64, which I have installed together with MSYS2.
After downloading and installing the boost libraries(1.76), I tried this example code (https://www.boost.org/doc/libs/1_76_0/more/getting_started/windows.html#build-a-simple-program-using-boost), which I built fine using this command:
g++ .\example.cpp -o test.exe -IC:\Users\Benelli\BoostLib\boost_1_76_0\boost_1_76_0
This example works on my system so I assumed that the boost libraries are installed correctly, although I did not build them, but I understood that the boost.test libary can be used as "header only".
I written a simple code following this tutorial:https://www.boost.org/doc/libs/1_76_0/more/getting_started/windows.html#build-a-simple-program-using-boost.
#define BOOST_TEST_MODULE const_string test
#include <boost/test/unit_test.hpp>
This code does not compile and I really do not get why. Is the boost.test library really "header_only"?
The command I used to build it was:
g++ .\boost_test_example.cpp -o boost_test.exe -IC:\Users\Benelli\BoostLib\boost_1_76_0\boost_1_76_0
Which gives this error message:
For the header only:
I think you need to use boost/test/included/unit_test.hpp as per the boost docs at https://www.boost.org/doc/libs/1_69_0/libs/test/doc/html/boost_test/adv_scenarios/single_header_customizations/multiple_translation_units.html
I had a similar winMain error and had to the define for BOOST_TEST_DYN_LINK to the top of the code (when i was linking against the libraries).
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE const_string test
#include <boost/test/unit_test.hpp>
When not using the header only for the undefined references link with the boost test library, eg -LC:/msys64/mingw64/lib -lboost_unit_test_framework-mt.

Problems with ffmpeg build in Xcode

Hi I have a problem with getting ffmpeg libraries to build in my Xcode project. It is in C++ . I have installed it using homebrew and have checked that all the correct libraries have installed via terminal. I have tried with and without extern C as I know it is a c library.
#include <iostream>
#include <opencv2/opencv.hpp>
#include <libavformat>
//extern "C" {
// #include <libavformat>
//}
The linker flags have been set by using (e.g. pkg-config --libs libavcodec) in terminal and these flags do not throw up an error when building. The header files are also found with no problems as the autocomplete flags them top while typing.
Please see attached pictures for Xcode build settings. Really stuck pease help
I identified the problem as being related to the path that the include statement relates to. The header files were one down in the hierarchy from the folders so:
#include <libavformat>
produces an error that the library was not found. The change below sorted the problem out.
#include <libavformat/avformat.h>

Unable to find Torch header files using nvcc

I'm trying to call some CUDA code from luaJIT (Torch) but I'm running into compiling issues. nvcc seems unable to find my Torch header files. I have CUDA 6.5 and gcc 4.4.7.
nvcc -o im2col -I/deep/u/ibello/torch/include im2col.cu
In file included from /deep/u/ibello/torch/include/THC/THC.h:4,
from utils.h:6,
from im2col.cu:1:
/deep/u/ibello/torch/include/THC/THCGeneral.h:4:23: error: THGeneral.h: No such file or directory
/deep/u/ibello/torch/include/THC/THCGeneral.h:5:25: error: THAllocator.h: No such file or directory
In file included from /deep/u/ibello/torch/include/THC/THC.h:7,
from utils.h:6,
from im2col.cu:1:
/deep/u/ibello/torch/include/THC/THCStorage.h:4:23: error: THStorage.h: No such file or directory
In file included from /deep/u/ibello/torch/include/THC/THC.h:9,
from utils.h:6,
from im2col.cu:1:
im2col.cu includes the following
#include "utils.h"
#include "common.h"
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
where "utils.h" is
#ifndef CUNN_UTILS_H
#define CUNN_UTILS_H
extern "C" { #include <lua.h> }
#include <luaT.h>
#include <THC/THC.h>
THCState* getCutorchState(lua_State* L);
#endif
This is relatively weird since the mentioned files are indeed in the include location I gave to the compiler..
ls /deep/u/ibello/torch/include/THC
THCAllocator.h THCDeviceTensor.cuh THCDeviceTensorUtils-inl.cuh THC.h THCReduce.cuh THCTensorConv.h THCTensorMath.h
THCApply.cuh THCDeviceTensor-inl.cuh THCDeviceUtils.cuh THCReduceAll.cuh THCStorageCopy.h THCTensorCopy.h THCTensorRandom.h
THCBlas.h THCDeviceTensorUtils.cuh THCGeneral.h THCReduceApplyUtils.cuh THCStorage.h THCTensor.h THCTensorSort.h
Any ideas about what I'm doing wrong?
Thx in advance!
It seems that this compile command:
nvcc -o im2col -I/deep/u/ibello/torch/include im2col.cu
did not give the necessary search paths for the compiler to find the header files like THGeneral.h that were located in /deep/u/ibello/torch/include/TH
The solution was to specify a compile command like this:
nvcc -o im2col -I/deep/u/ibello/torch/include -I/deep/u/ibello/torch/include/TH im2col.cu

go build doesn't find my C standard library when compiling cgo package

I'm trying to compile a go project in a raspberry pi.
The project has 5 files, two small .c files and its counterparts .h (one of these files is my code -- it calls the other, which is a base64 library) and a .go files which calls my .c code using cgo.
When I compile my C code only (with its calls and everything) with gcc alone at the raspberry pi it does well without any configuration.
When I compile the entire go project on my x86 Linux Ubuntu machine with go build, it also does pretty well.
But when I try to compile the go project with go build in the raspberry pi it doesn't get my C libraries:
fiatjaf#raspberrypi ~/g/s/b/f/project> go build -x
WORK=/tmp/go-build702187084
mkdir -p $WORK/bitbucket.org/fiatjaf/project/_obj/
cd /home/fiatjaf/go/src/bitbucket.org/fiatjaf/project
/usr/lib/go/pkg/tool/linux_arm/5c -FVw -I $WORK/bitbucket.org/fiatjaf/project/_obj/ -I /usr/lib/go/pkg/linux_arm -o $WORK/bitbucket.org/fiatjaf/project/_obj/base64.5 -DGOOS_linux -DGOARCH_arm ./base64.c
# bitbucket.org/fiatjaf/project
./base64.c:2 5c: No such file or directory: math.h
(If I put the <stdlib.h> before the <math.h> the problem occurs for it too, so the problem is not the absence of math.h, I think)
I tried to:
add // #cgo CFLAGS: -I/usr/include to the .go file
add // #cgo LDFLAGS: -I/usr/include (I can't discover what is the proper usage of these flags)
use go build -ldflags '-I/usr/include'
I don't understand why go is trying to compile base64.c with -I /usr/lib/go/pkg/linux_arm. Really don't. Someone help.
EDIT: Clarifying note about the structure of the project:
It has 5 files, 2 C (and its counterparts H):
base64.c
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
... // definitions of functions used at project.c
project.c
#include <stdlib.h>
#include <string.h>
#include "base64.h"
... // functions used at project.go
and 1 Go:
...
// #include <stdlib.h>
// #include <string.h>
// #include "project.h"
// #cgo CFLAGS: -I/usr/include
// #cgo LDFLAGS: -lm
import "C"
...
Where, what and how should I change in this declarations for this thing to work? And why did it worked on my x86 linux?
cgo inline syntax
The correct syntax for cgo parameters in the go file is this:
// #cgo CFLAGS: -I/usr/include
without the whitespace between # and cgo. See cmd/cgo for details on the syntax.
-ldflags parameter
The go -ldflags parameter passes parameters to the go linkers (5l, 6l, 8l, ...).
Even if the parameter would be passed to the C linker, this wouldn't do you any good
as the linker does not handle includes, the compiler does.
I'm afraid that this parameter won't help you here. All relevant parameters should
be configured in the go source file using the #cgo tags.
misc. notes
If you're using math.h you most likely need to link libmath. You can do this
by writing this to your go source file:
// #cgo LDFLAGS: -lm
It seems my problem was something related to not having set the CGO_ENABLED flag.
I don't know for sure, but it seems, because I uninstalled my Go from the Raspbian repositories (which seems to come with CGO disabled by default) and installed Go from source (just like I had made in my x86 Linux) then it started to work.

Compiling openCV 2.3.1 programs with MinGW gcc/g++ on Windows 7 64bit

For a week I've been struggling with compiling openCV programs. I've tried everything I could possibly find on the internet.
What I did is: I've downloaded OpenCV-2.3.1-win-superpack.exe and followed this official installation guide.
In the CMake (gui) my source was: D:\opencv and build destination was: C:\opencv.
I've also added C:\opencv\install\bin;C:\opencv\bin to my system's PATH variable.
What I want is to compile openCV programs on my Windows OS using MinGW's gcc/g++ compilers.
I've tried various gcc/g++ parameters that I've found on the internet and days playing with the -I and -L options the compiler can never find the openCV functions or structures.
What I am trying to compile:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char *argv[])
{
// Nothing but create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvWaitKey(0);
return 0;
}
Error:
Input:
gcc test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"
Output:
...\ccK4MfHv.o:test.c:(.text+0xa0b): undefined reference to `cvFree_'
Or with g++:
Input:
g++ test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"
Output:
...\ccXCTKa1.o:test.c:(.text+0x1e): undefined reference to `cvNamedWindow'
Side note: trying to compile in VS2005 I get the same error.
Thank you for your time!
In case someone else needs to solve this issue, here's how I got the posted OpenCV/HighGUI sample code to compile in Windows 7 x64 using MinGW, MSYS, and CMake:
build OpenCV from source using MinGW/MSYS/CMake. This is because I could not get the MinGW compiled version in the OpenCV-win-SuperPack to link properly in MinGW/MSYS/Windows 7 x64.
For full reference, here's how I compiled OpenCV:
make sure you have an up-to-date CMake (v2.6 or later) and MinGW (with GCC, G++, and MSYS options) installed
if you want the new Qt-based OpenCV HighGUI front-end, you will need to install Qt 4 (SDK).
download a OpenCV source/superpack version 2.2 or later (I used OpenCV-2.3.1-win-superpack.exe)
unzip the contents to [OPENCV_SOURCE_DIR] (I put it in C:/opencv, so there should be a file at C:/opencv/README for example)
create a [OPENCV_BUILD_DIR] directory elsewhere (I used C:/opencv/build/mingw)
use the CMake-GUI tool, specify the source directory as [OPENCV_SOURCE_DIR], the build directory as [OPENCV_BUILD_DIR], and click "Configure".
you may wish/need to go tweak the options (e.g. I ticked "Qt" and "Qt-OpenGL" entries, then clicked "Configure" again, then had to provide the path to the qmake executable)
once you have finished configuring OpenCV, click "Generate"
in a MSYS terminal, browse to [OPENCV_BUILD_DIR], and run "make" to build the code (this may take a while)
once the has been built properly, run "make install", which collects the built code/libraries/include dirs into [OPENCV_BUILD_DIR]/install folder (or a different folder if you changed the corresponding option when using the CMake-GUI tool)
add [OPENCV_BUILD_DIR]/install/bin folder to the PATH environmental variable. If you do not know how to do this, then I'd recommend using the Path Editor GUI tool.
if you end up using Qt, you will also need to put the bin folder of Qt SDK in the PATH environmental variable. This is the folder that includes qmake.exe.
put the following sample code into a file called test.c. I modified the includes slightly to make them compatible with OpenCV v2.2 and above.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
int main(int argc, char *argv[])
{
// Nothing but create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvWaitKey(0);
return 0;
}
in a MSYS terminal, browse to the folder where you put test.c, and run:
gcc -o test -I"[OPENCV_BUILD_DIR]/install/include" test.c \
-L"[OPENCV_BUILD_DIR]/install/lib" \
-lopencv_core[OPENCV_VERSION] \
-lopencv_imgproc[OPENCV_VERSION] \
-lopencv_highgui[OPENCV_VERSION]
So in my case:
gcc -o test -I"/c/opencv/build/mingw/install/include" test.c \
-L"/c/opencv/build/mingw/install/lib" \
-lopencv_core231
-lopencv_imgproc231
-lopencv_highgui231
Path Editor: http://www.redfernplace.com/software-projects/patheditor/
You have the directory, C:\opencv\install\bin, to locate libraries on the gcc/g++ command line, but I think you'll also need to specify the libraries to use as linker inputs as well. I'm not sure what libraries are part of the OpenCV distribution, but going by the example on the instruction page you linked to, one might be:
-lopencv_calib3d220.dll
You'll probably have to add one or more other ones (that follow the name pattern lib*.a in the C:\opencv\install\bin directory - or maybe some other lib directory that you should be passing in a -L option).

Resources