OPCUA sdk include path - c++

I have trouble with include uaplatformlayer.h in example from OPCUA client example.
I found this example in SDK. I tried to do own makefile, to build example client lesson01.
I use Visual Studio Code. It can't find this .h file.
#include "uaplatformlayer.h"
#include "sampleclient.h"
int main(int, char*[])
{
UaStatus status;
// Initialize the UA Stack platform layer
UaPlatformLayer::init();
// Create instance of SampleClient
SampleClient* pMyClient = new SampleClient();
return 0;
}
it still replies...
g++ -g -Wall -c client_cpp_sdk_tutorial.cpp
client_cpp_sdk_tutorial.cpp:1:10: fatal error: uaplatformlayer.h: Adresář nebo soubor neexistuje
1 | #include "uaplatformlayer.h"
| ^~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:9: client_cpp_sdk_tutorial.o] Chyba 1
The terminal process "bash '-c', '/home/michal/Dokumenty/OPCUA_adapter/sdk/examples/client_gettingstarted/lesson01/build.sh'" failed to launch (exit code: 2)
I think my problem is in makefile, but I don't have any idea where is the mistake.
Could anyone help me, please?
Does anyone experiance with OPCUA SDK?
cc=g++
cflags=-g -Wall
libflags=-L/home/michal/Dokumenty/OPCUA_adapter/sdk/lib -luamoduled -luamodelsd -lcoremoduled -luabasecppd -luastackd -lxmlparsercppd -luapkicppd -luaclientcppd -lxml2 -lssl -lcrypto
includes=-I/home/michal/Dokumenty/OPCUA_adapter/sdk/include/uabasecpp -I/home/michal/Dokumenty/OPCUA_adapter/sdk/include/uastack
objfiles=client_cpp_sdk_tutorial.o sampleclient.o
vystup=aplikace
%.o : %.cpp
$(cc) $(cflags) -c $<
# startovaci pravidlo
vychozi: $(vystup)
# zavislosti
dep:
$(cc) -MM *.cpp >dep.list
-include dep.list
clean:
rm aplikace $(objfiles)
# slinkování aplikace
$(vystup): $(objfiles)
$(cc) $(cflags) $(objfiles) $(includes) $(libflags) -o $#

You need to add "includes" to the recipe for the .o files:
%.o : %.cpp
$(cc) $(cflags) $(includes) -c $<

Related

SFML library doesn't link with makefile compilation

I have been trying to link the SFML dlls to my windows C++ project, but I can't get it to work. I always end up with:
fatal error: SFML/System.hpp: No such file or directory
I've tried a bunch of things but nothing changes the issue.
Here is my makefile:
PROGRAM = zero_flip
OBJS = src/main.o src/Math.o src/card.o src/game_board.o src/indicator.o src/ui.o
CXX = g++
CXX_FLAGS = -O0 -g -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable
LIB_DIRS = -L./Resources/libs/
LIBS = -lsfml-system -lsfml-graphics -lsfml-window -lsfml-audio
LNK_FLAGS = $(LIB_DIRS) $(LIBS)
DEPS=$(OBJS:.o=.d)
.PHONY: all clean
all: $(PROGRAM)
-include $(DEPS)
%.o: %.cpp
$(CXX) $(CXX_FLAGS) $(LNK_FLAGS) $< -o $#
$(PROGRAM): $(OBJS)
$(CXX) $(CXX_FLAGS) $(LNK_FLAGS) $^ -o $#
clean:
rm -f $(OBJS) $(DEPS) $(PROGRAM) && clear
The "./Resources/libs/" directory contains:
openal32.dll
sfml-audio-2.dll
sfml-audio-d-2.dll
sfml-graphics-2.dll
sfml-graphics-d-2.dll
sfml-system-2.dll
sfml-system-d-2.dll
sfml-window-2.dll
sfml-window-d-2.dll
Can anyone get me unstuck please this is driving me mad.
This is wrong:
%.o: %.cpp
$(CXX) $(CXX_FLAGS) $(LNK_FLAGS) $< -o $#
This rule says it will compile a source file into an object file, but the recipe actually builds a complete executable: it will compile the source file like xxx.cpp then link it into a program named xxx.o. You need to invoke just the compiler here, not the linker, so you should not have $(LNK_FLAGS) and you need to add the -c option to tell the compiler to stop after compiling and not link.
Then you need to add an -I option to the compile line telling the compiler where to find the header files needed during compilation... in this case SFML/System.hpp.

Makefile does not evaluate OBJECTS variable

I am trying to build a Makefile that will build a shared library with g++ and I find that it is not evaluating the OBJECTS variable. This is on Ubuntu 18.04 and all the files are in the same current directory. Secondly it is completely skipping the source file compilation and proceeding directly to evaluate the linking instruction. As a clarification I am using GNU Make 4.1
Here is what I get when I type make all
g++ -shared -pthread -o tree.so
g++: fatal error: no input files
compilation terminated.
Makefile:12: recipe for target 'tree.so' failed
make: *** [tree.so] Error 1
Here is my Makefile code
CC=g++
CFLAGS = -I/usr/local/include -Wall -std=c++17 -O3 -march=native -Ofast -ftree-vectorize
LIBS=-shared -pthread
SOURCES=$(wildcard *.cpp)
OBJECTS=$(wildcard *.o)
TARGET=tree.so
all:$(TARGET)
$(TARGET) : $(OBJECTS)
$(CC) $(LIBS) -o $(OBJECTS) $(TARGET)
$(OBJECTS):$(SOURCES)
$(CC) -c -g $(CFLAGS) $(SOURCES)
clean:
rm -f $(OBJECTS) $(TARGET)
If you only have the *.cpp files in your directories, then there is not any *.o yet, so your $(wildcard *.o) will expand to nothing.
What you want is to get the *.cpp files and compute the corresponding *.o files:
OBJECTS=$(patsubst %.cpp,%.o,$(SOURCES))
or equivalently:
OBJECTS=$(SOURCES:.cpp=.o)
Now, your compiler command is not the best one, because if you touch any source file all will be compiled. You can use instead:
$(OBJECTS): %.o: %.cpp
$(CC) -c -g $(CFLAGS) $< -o $#
So that only the touched files are actually rebuilt.
Also you have the linking command wrong. It should be:
$(TARGET) : $(OBJECTS)
$(CC) $(LIBS) -o $(TARGET) $(OBJECTS)
because the argument to the -o option is the output file, that is the target.

error: boost/regex.hpp: No such file or directory

I am trying to compile my C++ code using the GNU compiler under Linux using the following Makefile
CXX=gcc #icpc
RM=rm -f
CPPFLAGS=-g -O3 -fopenmp
CFLAGS= -Wall -c
OPENMP = -fopenmp
BIN = theVeecode_$(CXX)
LIBS= -L /path-to-boost/boost_1_53_0/stage/lib/ -lboost_regex
CPPSRCS=mathtools.cpp time_.cpp read_input.cpp vee_ao_calc.cpp vee_mo_calc.cpp write_int2e.cpp memory_check.cpp
OBJS=$(subst .cpp,.o,$(CPPSRCS))
OBJS+=$(COBJS)
all: $(BIN)
$(BIN): $(OBJS)
$(CXX) main.cpp $(OPENMP) -o $(BIN) $(OBJS) $(LIBS)
clean:
$(RM) $(OBJS) $(BIN)
dist-clean: clean
$(RM) $(BIN)
When I run the make command, I get the following error messages:
gcc -g -O3 -fopenmp -c -o read_input.o read_input.cpp
read_input.cpp:9:27: error: boost/regex.hpp: No such file or directory
read_input.cpp: In function 'void input::read_n_occ()':
read_input.cpp:95: error: 'boost' has not been declared
read_input.cpp:95: error: 'regex_search' was not declared in this scope
make: *** [read_input.o] Error 1
The read_input.cpp file starts with
#... // other includes
#include <boost/regex.hpp>
using namespace std;
namespace xxx
{
//some code here
}
The library path "/path-to-boost/boost_1_53_0/stage/lib/" contains the files
libboost_regex.a, libboost_regex.so and libboost_regex.so.1.53.0.
I don't understand why the compiler doesn't find the library files. Does anyone have any ideas why it's not working and how to fix it?
Thanks in advance.
As it turned out, the problem was in the Makefile. More specifically, the path to the boost library was not included during the compilation of the .cpp files using boost. Fixed it by adding the library explicitly in the compilation step:
%.o: %.cpp $(DEPS)
$(CXX) -c -o $# $< $(CPPFLAGS) $(LIBS)
Finally, the Makefile is as follows:
CXX=gcc #icpc
RM=rm -f
CPPFLAGS=-g -O3 -fopenmp
OPENMP = -fopenmp
BIN = theVeecode_$(CXX)
LIBS= -I /path-to-boost/boost_1_53_0/
LIBS+= -L /path-to-boost/boost_1_53_0/stage/lib/ -lboost_regex
CPPSRCS=mathtools.cpp time_.cpp read_input.cpp vee_ao_calc.cpp vee_mo_calc.cpp write_int2e.cpp memory_check.cpp
OBJS=$(subst .cpp,.o,$(CPPSRCS))
DEPS=Vector3.h mathtools.h memory_check.h read_input.h time_.h vee_ao_calc.h vee_mo_calc.h write_int2e.h
%.o: %.cpp $(DEPS)
$(CXX) -c -o $# $< $(CPPFLAGS) $(LIBS)
$(BIN): $(OBJS)
$(CXX) main.cpp $(OPENMP) -o $(BIN) $(OBJS) $(LIBS)
clean:
$(RM) $(OBJS) $(BIN)
dist-clean: clean
$(RM) $(BIN)
To get the word out there;
For my case, I was missing the libboost-dev package.
On debian, you can install it with sudo apt install libboost-dev

make error as: unrecognized option '-mcpu=arm1176jzf-s'

I am trying to compile some C to run on a friendlyARM for days now without any luck, i think im close but getting this error:
kevin#kevin-VirtualBox:~/Desktop/makef$ make
arm-none-linux-gnueabi-gcc -c -o obj/main.o main.c -I./
as: unrecognized option '-mcpu=arm1176jzf-s'
make: *** [obj/main.o] Error 1
Does anyone know how to what this error means and how to fix it?
steps i have tried:
1
touch *.*
make clean
make
(error as: unrecognized option '-mcpu=arm1176jzf-s)
2
touch *.*
make clean
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-l
(error as: unrecognized option '-mcpu=arm1176jzf-s)
the Makefile :
IDIR =./
CC=arm-none-linux-gnueabi-gcc
CFLAGS=-I$(IDIR)
ODIR=obj
LDIR =./
LIBS=-lgd -lrt
_DEPS = main.h Makefile
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJ = main.o serial.o fb.o menu_main.o timer.o cmdin.o buzzer.o statemachine.o inout.o network.o text_file_input.o text_file_input_oven.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: %.c $(DEPS)
$(CC) -c -o $# $< $(CFLAGS)
main: $(OBJ)
$(CC) -o $# $^ $(CFLAGS) $(LIBS)
.PHONY: clean
clean:
rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
It means the version of gcc that you have installed does not understand the option -mcpu=arm1176jzf-s
Either you have an older version of gcc which does not accept that option, or you have a version of gcc that has cross compiling support turned off.

g++: No such file or directory?

(On Linux, trying to set up SDL) I'm having a time with makefiles, I'm finding them hard to learn. Here is the error I'm getting.
g++: error: game.exe: No such file or directory
make: *** [game.exe] Error 1
Here is my makefile. (Any suggestions on making it better would be great. I've just kind of slapped together whatever I could find to work.)
#Game Make file
TARGET = game.exe
OBJS = App.o\
App_OnInit.o\
App_OnEvent.o\
App_OnLoop.o\
App_OnRender.o \
App_OnCleanup.o\
SDL_CFLAGS := $(shell sdl-config --cflags)
SDL_LDFLAGS := $(shell sdl-config --libs)
CFLAGS = -Wall -o
LIBS =
LDFLAGS =
$(TARGET): $(OBJS)
g++ $(CFLAGS) $(SDL_CFLAGS) $# $(LDFLAGS) $(OBJS) $(SDL_LDFLAGS) $(LIBS)
%.o: src/%.cpp
g++ -c $(SDL_CFLAGS) $< $(SDL_LDFLAGS)
.PHONY: clean
clean:
rm -f $(TARGET) $(OBJS)
You could either exchange $(CFLAGS) and $(SDL_CFLAGS) in the rule to make $(TARGET) or better remove -o from CFLAGS and put it directly before $#:
...
CFLAGS = -Wall
...
$(TARGET): $(OBJS)
g++ $(CFLAGS) $(SDL_CFLAGS) -o $# $(LDFLAGS) $(OBJS) $(SDL_LDFLAGS) $(LIBS)
-o option should immediately precede the name of the executable file to be produced. In your original Makefile it is part of $(CFLAGS) and is followed by the C flags of the SDL library. Therefore the compiler tries to link in game.exe (the $#) instead of producing an executable file by that name.