I want to conditionally compile some c++ code that uses boost, and make it so it doesn't try to compile the boost dependent code if boost is not present.
Does boost have any global macro that will be defined, like __BOOST__, that I can check for?
EDIT: It's clear to me now that I have to achieve this on the makefile level. I am working on OSX lion. Using gnu make
The TYPICAL way that this is done is to use a "configuration script" or similar, that detects if the required/optional component(s) is/are present, and then selectively sets some -D options to the build system.
Obviously, if it's just your own project or a small distribution, you could do the same thing manually.
You probably also need a couple of ifdef type of choices in the Makefile if there are library files that you need.
One of the easier ways to determine if a part of boost that you need is installed is to try to compile it. If there are errors, the likely cause is that that part of boost isn't present (this obviously doesn't work if there are more important parts missing - for example, not having a compiler or standard library installed will ALSO cause a compile to fail. This is why nearly all configure type tools "start with the most basic features, and work their way up the tree of dependencies").
Related
I've been searching around for different custom pre-processor extensions and replacements, but all of them seem to come with 1 of 2 caveats:
Either 1), you generate the code as a separate build-system, them manually put the output into your real (CMake) build system, or 2) you end up losing the builtin preprocessor for GCC.
Is there really no tool that can, say, run each file it gets against some configured script, then through cpp, then pass the result to gcc?
I'd love to use something like Cog by just setting an environment variable for gcc, indicating a tool that runs Cog first and then the standard preprocessor.
Alternatively, is there a straightforward way to accomplish that in CMake, itself? I don't want to have to write a custom script for each file, especially if I have to then hard-code the compiler/preprocessor flags in each target.
edit: For clarity, I am aware of several partial/partially-applicable solutions. For example, how to tell GCC to use a different preprocessor. (Or really, to look in a different place for its own preprocessor, cc1. See: Custom gcc preprocessor) However, that leaves a lot of work to do, to modify files, and then correctly invoke the real cc1, with the correct original arguments.
Since that is effectively a constant/generic problem, I'm just surprised there is no drop in program.
Edit 2: After looking over several proposed solutions, I am not convinced there is an answer to this question. For example, if files are going to be generated by CMake, then they can't be included and browsed by the IDE - due to not yet existing.
As ridiculous as it sounds, I don't think there is any way to extend the preprocessor short of forking Gcc. Everything recommended so far, constitutes incomplete hacks.
The GCC (C++ compiler) is made for compiling C++ programs. As the C++ preprocessor is standardized within the C++ standard there is usually no need for anything like a "plugin" or "extension" there.
Don't listen to the comments, that suggest you using any exotic extension to CMake or change source code of GCC. Running source files through a different program (cog in your case) before compiling is a well known task and all major build systems support it right away.
In CMake you can use the add_custom_command function. If you need this for more than one file, you could use a CMake loop like e.g. suggested in this answer.
I am trying to compile vhdl code using ghdl compiler. However I am missing two util libraries:
util.misc_conv_pkg and
util.vstring.
therefore this code is not working
LIBRARY util;
USE util.misc_conv_pkg.ALL;
USE util.vstring.ALL;
I have tried all possible installations methods I found:
http://ghdl.free.fr/site/pmwiki.php?n=Main.Installation
or
https://sourceforge.net/p/ghdl-updates/wiki/Installing%20ghdl/
But it is still not working. How do i fix this.
You need to find the source for those packages and compile them into the util library. They are part of the project you're working on, not part of VHDL.
If you can't find them, just comment out the USE clauses. Then one of two things will happen...
They aren't actually used at all, in which case the project will compile and work fine without them, and you have cleaned it up by eliminating unnecessary dependencies. It's amazing how often this is the case with those deprecated std_logic_arith packages.
Some functions or declarations from them are used, in which case compilation will fail with a fairly accurate description of what's missing. (Add the first few to the question if necessary).
Normally with a "util" library, the functionality is fairly obvious, so you can either find a more standard or more portable way of doing it, or you can write your own package that fulfils JUST the bits required for this project.
I have both C++ and C files in my project. I have separate and different compile flags settings for each, using CMAKE_CXX_FLAGS and CMAKE_C_FLAGS. How do I create different linker flags for each?
It would have been nice if something like CMAKE_CXX_EXE_LINKER_FLAGS and CMAKE_C_EXE_LINKER_FLAGS existed, but there is only CMAKE_EXE_LINKER_FLAGS.
There are
CMAKE_CXX_LINK_EXECUTABLE
CMAKE_C_LINK_EXECUTABLE
that look like they can solve your problems.
Keep in mind that you are getting into compiler and platform specific stuff, it's up to you to put the right combinations of conditional to select the right set of macros, if you need a multiplatform, multicompiler, project.
Build rules
It turns out in CMake version 3.0.2 at least, there are the following variables, CMAKE_C_LINK_FLAGS and CMAKE_CXX_LINK_FLAGS, used in ./share/cmake-3.0/Modules/CMakeCXXInformation.cmake.
They were not documented anywhere I had looked, and are not present in the generated files or cache, hence why I didn't find them. But they appear to do what I need.
Hopefully, CMake will continue to support them, and not remove them suddenly without warning, as is sometimes the case with undocumented features.
I have compiled a C++ program that need libboost-system1.46. I'm using Ubuntu 14.04 so I have libboost-system1.54. When I run the program it says that libboost_filesystem.so.1.46.1 was not found. How can I (if it is possible) to make the program work with libboost-system1.54. Perhaps there's a place where we specify which version to use. Is what I thinking is correct?
You need to recompile against the newer version of library. AFAIK boost libraries are not binary compatible between versions, so simple . You could do tricks, to use the other version (symbolic links or other magic), but it would most probably not work.
So you either need to provide the version that is required or change the requirement - recompilation.
If you wrote the program, or built it, you just need to repeat the whole build procedure, with all the configures before the make or compilation. Technically, just relinking should work, but some systems like CMake cache the configuration options evaluated at this step, and simply, calling make again would not work. So I would suggest to repeat whole process.
Whatever the procedure looked, it should suffice just to repeat it.
You may be able to create a symbolic link which points the name libboost-system1.46 to libboost-system1.54.
This will work as long as the interfaces for the functionality you're using hasn't changed, though is probably not a good idea. It may work just get your code going and tested, but would never be appropriate for any sort of release software.
You should try to recompile your program with the newer version of boost.
We have a C++ template library that has some features that depend on zlib, for example.
We selectively enable and disable features using preprocessor symbols, i.e. setting -DHAVE_ZLIB=1 on the command line.
Our CMake-based build system recognizes installed zlib and adds the according flag to the compiler.
Of course, this can also be done manually by users, using their favourite IDE or their Makefiles.
One property of the library is that the code that uses zlib is interleaved with the code not using zlib, i.e. using #include <library/header.h> should work regardless of zlib being present or not.
Currently, we #if out code that depends on zlib.
Thus, if the user tries to use something like CompressedStream, for example, the class is simply not found.
This is quite frustrating for users.
The build system warns them that zlib could not be found, but users being users either do not see this or forget it quickly.
I myself have fallen into this trap, too.
Now to my question:
What is the best way to warn the user that zlib is disable if he tries to use code requiring zlib.
The only thing I can think of is using the deprecator marker mechanisms implemented in many compilers.
Although different syntax is required for each of them, this could easily be abstracted away using preprocessor macros.
Is there any other good way?
The solution only has to work in VS >8, GCC >4.2 and LLVM.
The proper place to warn users about such things is (IMO) build system. Take a look at Ogre3D, KDE and many other projects - all of them print sort of outline after configuration of build. This outline contains information on what is found and what is not and what are consequences of this.
Even Qt don't do anyting to fix this. There is option to build Qt with STL support and if it's not built such way, there are no warnings or whatever, only compile errors regarding undefined methods. So, i think, there is no way to warn user about such things during compile phase.