Why doesn't pkg-config support CXXFLAGS? - pkg-config

I noticed that pkg-config only offers CFLAGS and LIBS (aka LDFLAGS).
Why aren't there any support for pkg-config to offer CXXFLAGS?

yea, question was over a year ago
IMHO - this should be fixed but that will take a long time. Meanwhile you will come across conflicting flags. The best example of conflicting flags I can think of is the "--std=???" option - which when used wrong, causes warnings.
Step 1- Put both "--std=c99" and "--std=c++11" in the PC file.
Step 2- Require uses to do the following in their Makefile
PKG_CFLAGS := $(shell pkg-config --cflags FILENAME.pc)
CFLAGS := $(filter-out --std=c99, ${PKG_CFLAGS})
CXXFLAGS := $(filter-out --std-c++11,${PKG_CFLAGS})
Problem: This does not play well with autoconfig, and Cmake based stuff :-(

Related

How to add C++ Runtime Libraries specification (for Android NDK) in makefile

I'm trying to use this existing library in my Android Application. It is a rather big library with a lot of code, and it's own makefile, changing all of that would be too much effort. That is why I want to adjust the Makefile so that it gets cross-compiled for Android devices.
First I want to start small and try to compile some example with this library and see if it runs on the Android device.
Here some parts that I thought are to be changed/added to the compiler and the flags:
CXX := ${ANDROID_NDK_TOOLCHAINS}/bin/clang++
CXX := ${ANDROID_NDK_TOOLCHAINS}/bin/clang
CFLAGS := -fPIE -fPIC -pie
CXXFLAGS := -fPIE -fPIC -pie
CXXFLAGS += --target=armv5te-none-linux-androideabi --gcc-toolchain=/home/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
CFLAGS += --target=armv5te-none-linux-androideabi --gcc-toolchain=/home/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
If I do not use the last two flags, compilation works, but I can only run the example on my pc, copying it to the Android device and starting it via console will give an error, that it was not compiled for this device.
So far that makes sense.
After adding the last two lines, it will abort and say:
fatal error: 'vector' file not found
Some research says that I have to tell the ndk compiler which C++ Runtime Libraries (https://developer.android.com/ndk/guides/cpp-support.html#c_runtime_libraries) it should use.
But how can I add this to my makefile? If I try to add it like it is added to Application.mk (http://mobilepearls.com/labs/native-android-api/ndk/docs/CPLUSPLUS-SUPPORT.html):
APP_STL := gnustl_static
Then it will still not find the vector class.
Do I have to add it differently? Is it possible to include it with just some flag?

automake: distcheck with CPPFLAGS

I am looking for something like DISTCHECK_CONFIGURE_FLAGS but more flexible.
I am using an external package in my program. Let's say foo and on my laptop it's installed to ${HOME}/soft/foo.
configuring with the autotools is simple:
./configure CPPFLAGS=-I${HOME}/soft/foo/include LDFLAGS=-L${HOME}/soft/foo/lib
but distcheck is giving me headaches. When distcheck unpacks and configures, how do I tell it to use my CPPFLAGS and LDFLAGS?
DISTCHECK_CONFIGURE_FLAGS is close, but incorrect: other maintainers might have the foo library installed under /opt/ or /software/random/whatever or /usr/local/foo-master and I don't want to impose my environment on other maintainers.
The answer is to not hard-code anything in the Makefile.am. Automake will inherit several environment variables from autoconf.
All one needs to do is pass the CPPFLAGS and LDFLAGS used to configure the package:
DISTCHECK_CONFIGURE_FLAGS = CPPFLAGS=${CPPFLAGS} CFLAGS=${CFLAGS}\
${CXXFLAGS}=${CXXFLAGS} LDFLAGS=${LDFLAGS}
and now 'make distcheck' will use the requested flags and find the headers and libraries for the desired package.

cflags reference for writing makefiles

GNU Make 3.82
Hello,
Is there any reference materials for finding the description of CFLAGS. I am editing someones makefile and I have this CFLAGS options. However, I just want to find a description of these to find out what they do.
sample: -Isrc -rdynamic, etc
Can anyone link me to any websites or online manuals?
Many thanks for any suggestions,
They are passed to the compiler so you need to check the documentation for the specific compiler. However it looks like you are using GCC so the following may be helpful:
http://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html#Invoking-GCC
In this particular case -I is covered under directory options and -rdynamic is covered under link options.

Header file not found when building under cygwin

I am trying to build a certain library under cygwin (OpenEXR), and I get the following error:
b44ExpLogTable.cpp:52:18: error: half.h: No such file or directory
half.h is referenced using #include <half.h>, and is actually a part of another library I successfully run make/make install on previously.
The question is -- when using #include with <>, where the preprocessor expects to find the specified file?
(I have just found it in /usr/local/include/OpenEXR, but I have no idea why preprocessor cannot).
Update: I have also found:
Makefile
ILMBASE_CXXFLAGS = -I/usr/local/include/OpenEXR
Makefile.am
INCLUDES = #ILMBASE_CXXFLAGS# \
-I$(top_builddir) \
-I$(top_srcdir)/config
This actually decreased my understanding of what the problem may be.
Update 2: So, by redefining some variables in makefile I found out that instead of $(CXXCOMPILE) make seems to run $(CXX) $(CXXFLAGS), with CXXFLAGS being just -g -O2. Ok, I have no idea how it manages to run $(CXX) $(CXXFLAGS) if this combination in not used anywhere in the makefile except in $(CXXCOMPILE) which is not run. I can add my -I to CXXFLAGS but I have a feeling that a lot more additions will be required, so I would prefer to find a root cause of the problem.
(I am not sure whether it is a Super User or Stack Overflow question, because my developer skills in C++/Linux are almost non-existent.)
Additional include directories are usually specified in CPPFLAGS. Try running ./configure CPPFLAGS=-I/usr/local/include/OpenEXR and re-running make.
You need to somehow get -I/usr/local/include/OpenEXR added to the compiler command line. That might be a simple matter of doing:
CFLAGS=-I/usr/local/include/OpenEXR make

Removing Flag in GCC using Pragma

I want to remove a compiler flag for a praticular file in my project. How to do this using #pragma?
Sorry that this is late, but I just ran into the same issue on my project.
I couldn't find a #pragma to modify the list of compiler flags, but I could use GNU Make's ability to modify make variables on a per-target basis.
One of my files was taking forever to compile with -fvar-tracking-assignments (which was added to -O2 a few releases back). I was looking for a way to turn that off for one file; after looking (in vain) for an appropriate pragma, I simply added this line to my makefile to modify CXXFLAGS when compiling and linking those specific files:
ObtuseObj.o ObtuseObjTest.o ObtuseObjTest : CXXFLAGS += -fno-var-tracking-assignments
Hopefully this will be helpful to others!
Only flags that control warnings can be overridden using #pragma, see the diagnostic pragmas documentation page.
For instance, you could do:
#pragma GCC diagnostic ignored "-Wformat"
To make GCC ignore the warnings generated by mismatched formatting strings.
I'm not sure if gcc has such pragmas. I can't find any on the gcc page for pragmas.
If you are asking a question related to gcc next time, tag it under gcc as well. I would tag it but I can't. Tagging under gcc would get you many more responses.

Resources