makefile no such file or directory: libxml/xmlstring.h - c++

I'm not used to making makefiles. My old project had all the makefiles in place and I'm making this from scratch for a small test with a lot of canned lib dependencies that I'm not used to either. It's been a few years since I looked at makefiles.
I have a directory called libopcTest with the following in it:
LibOPCTest.cc
LibOPCTest.h
makefile
makefile has this in it:
INC=-I/usr/include/libxml2/libxml
LIB=-L/usr/include/libxml2/libxml
all: LibOPCTest.exe
LibOPCTest.exe: LibOPCTest.o
>tab> gcc -o LibOPCTest.exe LibOPCTest.o
LibOPCTest.o: LibOPCTest.cpp
>tab> gcc -c $(INC) $(LIB) LibOPCTest.cpp
clean:
>tab> rm LibOPCTest.o LibOPCTest.exe
I looked in /usr/include/libxml2/libxml and it does have xmlstring.h in it. I don't see the libxml reference in opc.h, but apparently that's where it comes in, presumably in an include file, like config.h.
Plus, we have LibOPCTest.cpp which #includes <opc/opc.h> and it's own .h file.
main is in LibOPCTest.cpp.
When I type make at the Linux command prompt, I get the following error:
In file included from /usr/include/opc/opc.h:36:0, from LibOPCTest.cpp:1:
/usr/include/opc/config.h:37:30: fatal error: libxml/xmlstring.h: no such file or directory.
Shouldn't I have the libxml with the LIB and INC definition in the makefile pointing to libxml? I don't think I'm supposed to add anything to opc.h, including build it, since it's a canned library.
I was looking at this makefile example, and I think I have everything I need (probably not since it's not building).
I know it's a basic question, but hopefully someone has a good suggestion. Thanks for being nice in advance!!

We decided to put the Linux version of libOPC on hold because there isn't a good 64 bit version and it needs a lot of work.

Related

How do I use GCC options -iprefix and -iwithprefix?

I have a c++ application that is separated into modules. The directory structure for each module looks like this:
module_a/
export/ <-- module_a public interface
src/ <-- module_a private source
test/
src/ <-- unittests for module_a
I'm using CMake to setup the module dependencies and to build the application. If module_a depends on module_b then module_b's export directory is added as include path when building module_a.
So, if there is a file module_b/export/foo.h that module_a needs then in a source file you will use #include "foo.h".
I'm looking for a way to to make so that the module name is part of the include directive. So for the above example I want to (have to) write #include "module_b/foo.h".
Is this something that can be done with GCC option -iprefix and -iwithprefix? I've searched for usage examples but all I can find is copies and references back to the GCC manual, which I think doesn't explain it very well.
I have tried to use it this way:
$ find -type f
./src
./src/main.cc
./export
./export/bar.h
$ g++ -iprefix foo/ -iwithprefix export/ src/main.cc
src/main.cc:1:10: fatal error: foo/bar.h: No such file or directory
1 | #include "foo/bar.h"
| ^~~~~~~~~~~
compilation terminated.
$ gcc --version
gcc (Debian 9.2.1-17) 9.2.1 20191102
But as you can see, it doesn't work. How should I use -iprefix and -iwithprefix?
Also, does anyone have another solution to my problem? I'm a bit worried that IDEs and other compilers might not understand -iprefix and -iwithprefix, so any other solutions are welcome as well.
Edit: after posting this question I immediately realized that perhaps -iprefix foo/ -iwithprefix bar is just a fancy way of writing -I foo/bar. However, I tested that and I still didn't get it to work. So it would still be good if someone could explain how these options works, even if they are not going to help me for my problem.
How should I use -iprefix and -iwithprefix?
It's just a shortcut to avoid having to write out a common prefix every time. So instead of:
cpp -Idirafter /sys/root/a -Idirafter /sys/root/b
You instead do:
cpp -iprefix /sys/root/ -iwithprefix a -withprefix b
(substitute -Iwithprefix for -Iwithprefixbefore if you want it to be equivalent to -I instead.)
This can come on handy with very long include directory paths like you may run into when cross-compiling (and may be even required, cf. getconf ARG_MAX)
Also, does anyone have another solution to my problem?
I stumbled upon -iprefix, because I've the same problem you have as well and hoped there would be an out-of-the-box option for that. There isn't, but Linux device tree builds have the same issue:
The device trees for ARCH=arm and ARCH=arm64 are in arch/arm/boot/dts and arch/arm64/boot/dts, respectively. Sometimes, arm64 device trees need some common file from the arm directory, but having the dts directories of all architectures in path isn't that great a solution.
What Linux does instead, is having a dedicated directory in the source tree with suitably-named symlinks into each architecture and this directory's path as well as the directory of the currently active ARCH go into the search path. That way, ARCH=arm can write #include "something.dtsi", but ARCH=arm64 has to write #include <arm/something.dtsi> instead.

Modifying the "priorities" between include directories within a Makefile

To make it simple, I want to use the OpenCV libs within my embedded ElinOS system, while programming on my Windows machine.
To do so, I downloaded OpenCV sources for Linux on the website and I'm trying to compile it using cygwin and cmake to generate the Makefile. However, I have an error occuring during the "make" step, which is /usr/include/wchar.h:41:25: fatal errorĀ : bits/wchar.h : No such file or directory
I understand the problem, which is basically that cygwin should use /opt/elinos-6.0/cdk/x86/x86_64/eglibc-2.17/x86_64-unkown-linux-gnu/include instead of /usr/include but I have basically no idea how to change that.
That far, I added those two lines to the CMakeLists.txt
set(CMAKE_INCLUDE_DIRECTORIES_BEFORE ON)
include_directories(BEFORE C:/sysgo/opt/elinos-6.0/cdk/x86/x86_64/eglibc-2.17/x86_64-unkown-linux-gnu/include/)
and this line to the builded Makefile:
INC = -I/cygdrive/c/sysgo/opt/elinos-6.0/cdk/x86/x86_64/eglibc-2.17/x86_64-unknown-linux-gnu/include/
But it didn't work, I still got the same error. Any help is welcome, and I would be glad if an explanation comes with the magic command line(s) that will help.
Thanks in advance!
one way for you might be to clear the standard include path completly:
first delete standard path with -nostdinc and then put your own directories in it.
you might not want loose all of them, here is a way to see which are used in the standard include path: echo "//" | gcc -xc++ -E -v - (works also with clang)
Here is a fine article for this for gcc :
http://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art026
here you can read it works with clang too:
http://clang.llvm.org/docs/CommandGuide/clang.html

Error when running make for my Makefile.cpp

I'm getting the error "No targets specified and no makefile found. Stop."
however I'm running the "make" command for my Makefile.cpp in the same directory.
So I just wanted to do a simple makefile to run my three separate files:
all:
g++ gameoflife.cpp functions.cpp header.hpp -o gameoflife
The second line is tabbed once.
Let me know if I need to rename the files or how exactly to run the make file correctly. Thanks. Also this is all being run in a UNIX server with make installed, etc.
The make command uses the makefile with the the name that you specify with the -f option. If you don't use the -f options it uses the file Makefile without the .cpp appendix.
Your editor might have save your Makefile as Makefile.cpp. Check that you use the correct name.
Edit:
To be more specific: The GNU make searches for one of these files in that order:
GNUmakefile
makefile
Makefile

makefile which build the library (lib.a)from the list of object files (*.o)

I have a problem because i have never written any makefile. So if any could help me I become happy. I have a lot of different .o files, which stored in the different folders. For example:
folder1: obj1.o
folder2: obj2.o
folder3: obj3.o
I need makefile, which will build the library from files which I send to makefile like param. Param should be makefile too and include info about folders where stored necessary files.
For example I would like to build lib from objects stored at folder1 and folder2 without folder3. So makefile which I send as param to the main makefile must include routes to folder1 and folder2:
local_libs := ../folder1
local_libs += ../folder2
main makefile should parse that info and call libtool utilite for creating lib from files at this folders. Could anybody help?
I suppose it is easy for realization, example will be great!
You need a rule that inputs the .o files, outputs the .a file and calls the ar command to do the work. Something like:
lib.a: $(OBJECTS)
${AR} -cr ${#} ${^}
GNU make does not support passing parameters "to the makefile" on the command line.
You have two basic mechanism for setting parameters to be used by make while executing a makefile (I'm assuming that you are using GNU make, and not all of his advice will apply to other makes):
Write to submakefiles, possibly using a script. If you makefile has a line like
include file.mk
gmake will include the contents of file.mk. Change the contents of file.mk and you change the behavior of your makefile.
Make can take variable values from environment variables when set. This provides a powerful mechanism for letting the user customize the behavior of your makefile.

How do I link against libtool static la library?

I have compiled this library successfully. It generates a libcds2.la file that I am trying to link into my own project. I have all files (including the .h file) in the same directory as my project file. When I try to link and use the functions of said library, using:
g++ -o test -I/opt/include/ -L/opt/lib/ -lcds2 libcdsNoptrs.cpp util.cpp
comes back with
./test: error while loading shared libraries: libcds2.so.2:
cannot open shared object file: No such file or directory
whatever that is. But the point is that most of the time it just doesn't recognize the library. I assume I'm doing something wrong with the file paths, but can't figure it out. My test file is a C++ file including #include "libcds2/array.h" and everything is installed in opt/lib, opt/include, ugly, I know, but that's what the Makefile generated.
Any pointers?
The libtool .la is a 'meta data' file. After building the cds2 library, it's expected that libtool will also be used in 'link' mode to build any of the package's tests, etc.
Typically, the in the directory you find the .la file, you will find the .a and .so under the .libs subdirectory. The .libs/libcds2.a file will be found there, provided configure was given the --enable-static option (or it is enabled by default). But, my understanding is that you've installed the package in /opt :
g++ -I/opt/include/ libcdsNoptrs.cpp util.cpp -o test /opt/lib/libcds2.a
Otherwise, if libcds2 isn't installed, just supply a path to: .../libcds2/lib/.libs/libcds2.a
Unless you want to use libtool in --link mode with -static to handle everything. But learning the advantages of libtool is usually an exercise for a rainy day:)