Cmake not using the right boost library - c++

I have two versions of boost:
The first one (from xcode i guess) has files in /usr/local/include/boost and
/usr/local/lib/boost
The second one (from homebrew) has files in
/usr/local/Cellar/boost/1.54.0/include/boost and
/usr/local/Cellar/boost/1.54.0/lib
As I want to use the second one, I call cmake to create my makefile and i compile my project this way:
cmake -DBOOST_ROOT=/usr/local/Cellar/boost/1.54.0/ .
make
And I get this error:
/usr/local/include/boost/functional/hash/extensions.hpp:54:17: error:
variable 'hash_value' declared as a template
std::size_t hash_value(std::list<T, A> const& v);
^
Clearly the boost version that is used is not the one I mentioned using BOOST_ROOT . How do I make sure that the version of boost that is used is the one in /usr/local/Cellar/boost/1.54.0/ ?
Thanks in advance

My guess is that you have another dependency that requires -I/usr/local/include/ in the flags, and that that -I flags is seen by the compiler before -I/usr/local/Cellar/boost/1.54.0/include.
Debug your compilation process with:
make VERBOSE=1
to see the compilation commands that are used.

Related

cmake target_link_libraries causes compiler error in target

I would like to use Open3d in LAMMPS. Open3D details how to find the pre-installed Open3D package using cmake.
Using the above, I have written a cmake file that I believe LAMMPS uses during its build stage to find packages and link them. Curiously, the line
target_link_libraries(lammps PRIVATE Open3D::Open3D)
appears to cause the compiler to find errors in the LAMMPS src code, i.e.,
/home/USER/lammps/src/fmtlib_format.cpp:58:51: error: duplicate explicit instantiation of ‘struct fmt::v7_lmp::detail::basic_data<void>’ [-fpermissive]
58 | template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>;
If I comment the target_link_libraries statement, the code compiles just fine (but doesn't link to Open3D). Apologies for being unable to provide a MWE as I do not know how to replicate this behaviour in a simple manner. Could you please explain to me why the target_link_libraries command causes the compiler to find errors in the LAMMPS src code and provide a solution to prevent this from occuring? If relevant I am using Clion 2021.1.2 and
CMAKE_CXX_COMPILER_VERSION = 9.3.0
CMAKE_CXX_STANDARD = 11
CMAKE_VERSION = 3.19.2

Why am I getting this error with MinGW and Cmake?

So I am trying to compile this flip fluids addon with blender, so I followed this tutorial, https://www.youtube.com/watch?v=TVKM1egDoGs , So I first ran cmake.exe -G "MinGW Makefiles" .. and it was telling me that it was missing a CMakeLists File... So I added one... then I ran cmake.exe --build . and it got to 3 percent than showed me errors like ...
In file included from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/threadutils.h:29,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/meshlevelset.h:65,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/meshobject.h:30,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/fluidsimulation.h:38,
from C:\Users\N\Downloads\Blender-FLIP-Fluids-master\src\engine\c_bindings\fluidsimulation_c.cpp:25:
C:/PROGRA~2/MINGW-~1/I686-8~1.0-P/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/mutex:93:9: note: previous definition of 'class std::recursive_mutex'
class recursive_mutex : private __recursive_mutex_base
^~~~~~~~~~~~~~~
In file included from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/mingw32_threads/mingw.condition_variable.h:25,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/threadutils.h:31,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/meshlevelset.h:65,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/meshobject.h:30,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/fluidsimulation.h:38,
from C:\Users\N\Downloads\Blender-FLIP-Fluids-master\src\engine\c_bindings\fluidsimulation_c.cpp:25:
C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/mingw32_threads/mingw.mutex.h:142:44: error: conflicting declaration 'typedef class std::_NonRecursive<std::recursive_mutex> std::mutex'
This is the full error https://pastebin.com/KTnALG1E, where is this coming from?? is it a mingw error or what? Can someone help please?
Your full error message includes a more interesting bit:
C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/mingw32_threads/mingw.thread.h:32:2:
error: #error This version of MinGW seems to include a win32 port of
pthreads, and probably already has C++11 std threading classes
implemented, based on pthreads. It is likely that you will get class
redefinition errors below, and unfortunately this implementation can
not be used standalone and independent of the system header,
since it relies on it for std::unique_lock and other utility classes.
If you would still like to use this implementation (as it is more
lightweight), you have to edit the c++-config.h system header of your
MinGW to not define _GLIBCXX_HAS_GTHREADS. This will prevent system
headers from defining actual threading classes while still defining
the necessary utility classes.
So either install a different version of mingw or edit your mingw files according to the instructions above.

Missing C++ std library methods and other errors while compiling EOS on Ubuntu 14.04?

I'm trying to compile the EOS blockchain/smart contract project on GitHub on Ubuntu 14.04:
https://github.com/EOSIO/eos
After getting Clang 4.0 to install, installing build_essentials, and upgrading CMake to 3.5, I was able to run the build process without any missing dependencies. However, now I get the errors shown below when I build the EOS source. This seems to me like another general issue with the configuration of the tools on my system since many people are able to compile the EOS code, although usually on Ubuntu 14.04.
Can anyone tell by looking at the errors I'm getting what tool or library I need to install or upgrade?
In file included from /usr/lib/llvm-4.0/include/clang/AST/Decl.h:31:
/usr/lib/llvm-4.0/include/llvm/Support/TrailingObjects.h:259:33: error: 'BaseTy' does not refer to a value
static_assert(LLVM_IS_FINAL(BaseTy), "BaseTy must be final.");
^
/usr/lib/llvm-4.0/include/llvm/Support/TrailingObjects.h:233:20: note: declared here
template <typename BaseTy, typename... TrailingTys>
^
/usr/lib/llvm-4.0/include/llvm/Support/TrailingObjects.h:259:19: error: expected expression
static_assert(LLVM_IS_FINAL(BaseTy), "BaseTy must be final.");
^
/usr/lib/llvm-4.0/include/llvm/Support/type_traits.h:104:45: note: expanded from macro 'LLVM_IS_FINAL'
#define LLVM_IS_FINAL(Ty) std::is_final<Ty>()
^
Linking CXX executable codegen
/home/robert/Documents/GitHub/eos/programs/launcher/main.cpp:405:18: error: no template named 'underlying_type_t' in namespace 'std'; did you mean
'underlying_type'?
using T = std::underlying_type_t <enum_type>;
~~~~~^~~~~~~~~~~~~~~~~
underlying_type
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/type_traits:1855:12: note: 'underlying_type' declared here
struct underlying_type
^
/home/robert/Documents/GitHub/eos/programs/launcher/main.cpp:435:17: error: no member named 'put_time' in namespace 'std'
dstrm << std::put_time(std::localtime(&now_c), "%Y_%m_%d_%H_%M_%S");
~~~~~^
[ 64%] Building CXX object libraries/chain/CMakeFiles/eos_chain.dir/chain_controller.cpp.o
/home/robert/Documents/GitHub/eos/programs/launcher/main.cpp:406:39: error: no matching conversion for static_cast from 'allowed_connection' to 'T'
(aka 'underlying_type<allowed_connection>')
return lhs = static_cast<enum_type>(static_cast<T>(lhs) | static_cast<T>(rhs));
^~~~~~~~~~~~~~~~~~~
The Missing _t alias names look like you’re having issues with C++14. The header paths in the error messages look like you’re using the standard library from GCC 4.8 (the default compiler on Ubuntu 14.04), which is simply too old.
I can see two solutions:
Switch from GCC’s libstdc++ to an up-to-date version of LLVM’s libc++. I’m not familiar enough with Ubuntu to tell you how to install it. For the compilation of EOSIO you must pass the -stdlib=libc++ option to Clang to switch to the different stdlib. EOSIO looks like it’s using CMake, so you have to include -DCMAKE_CXX_FLAGS=-stdlib=libc++ in your CMake command line.
Use the Toolchain test builds PPA to install a newer GCC and and libstdc++ in addition to your system’s default one. For Ubuntu 14.04 GCC 7.2.0 is the latest version available, which is perfectly C++14 capable. Add the PPA to your package sources and then do a:
sudo apt-get install gcc-7 g++-7
This installs both the GCC C compiler and C++ compiler along with the stdlib. Your default compiler is still going to be the old GCC 4.8, so you’ll have to tell CMake about the newer versions:
-DCMAKE_CXX_COMPILER=g++-7 -DCMAKE_C_COMPILER=gcc-7
Note that now you compile EOSIO with GCC (and the new stdlib) instead of Clang. Instructing Clang to use a specific version of libstdc++ should be possible, but I don’t know how.
Official support is for Ubuntu 16.10. Consider upgrading.
(EDITED: I mistakenly said 14.10)
Source: https://github.com/EOSIO/eos/wiki/Local-Environment#211-ubuntu-1610

How to use nvcc as compiler in ns3

I'm trying to use cuda in ns3, but when I tried to run CXX="nvcc" ./waf configure, it shows the following message on the screen:
Checking for 'g++' (C++ compiler) : not found
Checking for 'clang++' (C++ compiler) : not found
Checking for 'icpc' (C++ compiler) : not found
could not configure a C++ compiler!
(complete log in /home/kelu/workspace/ns-3.24/build/config.log)
I checked the config.log, it says the following:
Checking for 'g++' (C++ compiler)
find program='nvcc' paths=['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin', '/usr/local/cuda/bin'] var='CXX' -> ['nvcc']
from /home/kelu/workspace/ns-3.24: Could not determine the compiler type
not found
----------------------------------------
Checking for 'clang++' (C++ compiler)
find program='nvcc' paths=['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin', '/usr/local/cuda/bin'] var='CXX' -> ['nvcc']
from /home/kelu/workspace/ns-3.24: Not clang/clang++
not found
----------------------------------------
Checking for 'icpc' (C++ compiler)
find program='nvcc' paths=['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin', '/usr/local/cuda/bin'] var='CXX' -> ['nvcc']
from /home/kelu/workspace/ns-3.24: Not icc/icpc
not found
from /home/kelu/workspace/ns-3.24: could not configure a C++ compiler!
nvcc is located in /usr/local/cuda/bin, which is in path. But it seems to me that the building script of ns3 does not resolve nvcc as a compiler.
Could anybody please tell me the right way to make nvcc the CXX compiler in ns3?
Thanks.
Your problem probably was that Waf actually checks the compiler's built-in #defines to check whether a compiler invoked as "gcc" actually is gcc or not. As a concrete example, it will error out if it detects that the compiler is Intel's icc (because it #defined __INTEL_COMPILER) but was invoked with a "gcc" command line!
The code that does the identification is at https://waf.io/apidocs/_modules/waflib/Tools/c_config.html#get_cc_version .
So, if you don't have a compiler which tries hard to look like one of the supported ones, looks like you are supposed to write your own Waf tool.
However, you can try to hack your way through. For example, let's say that your compiler is compatible enough with gcc but still it doesn't get past Waf's absurdly stringent test. A fix is to run "waf configure" using the real gcc, and then edit the file where Waf stores the detection results, so at the build step Waf will actually run your compiler instead of gcc. You can do this by editing build/c4che/_cache.py: change the CC definition to your compiler's full path.
I haven't found a way to use nvcc in ns-3, but I did find a work around for this problem. I'm happy to share my solution here to help others:
Make your cuda code a static library:
ar rcs libcudacode.a a.o b.o c.o (you need to make the *.o files first using g++, nvcc, or anything else you want)
put libcudacode.a in /your/lib/folder/ and put your cuda code in /your/src/folder
Add lib folder and src folder into waf:
CXXFLAGS_EXTRA="-I/your/src/folder -I/your/cuda/dir/include" LINKFLAGS_EXTRA="-L/your/lib/folder -L/your/cuda/dir/lib64 -lcudacode -lcudart" ./waf configure.
./waf
Your code should be compiled now. You can access any public functions in your cuda code by #including "corresponding_header.h"
A little bit explanation:
CXXFLAGS_EXTRA and LINKFLAGS_EXTRA add compilation flags in ns-3's compiling system. You need to add both your cuda code and NVidia's cuda library to use the functions.
If you used any other libraries, also put them in CXXFLAGS_EXTRA and LINKFLAGS_EXTRA
Check the cuda directory name in your system. It's probably not lib64 in your machine.

MacPorts clang not using its own headers

I'm trying to get emscripten to work on OS X 10.8, see this post for some related issues there. Apparently the clang++ version shipped with Xcode is too old, so I got a recent clang 3.7.0 using MacPorts. I even told CMake to use that compiler (passing -DCMAKE_CXX_COMPILER=clang++-mp-3.7 on the command line), but it still fails:
[ 33%] Building CXX object CMakeFiles/optimizer.dir/parser.cpp.o
/opt/local/bin/clang++-mp-3.7 -std=c++11 -fno-exceptions -fno-rtti -O3 -DNDEBUG
-o CMakeFiles/optimizer.dir/parser.cpp.o
-c …/emsdk/emscripten/master/tools/optimizer/parser.cpp
In file included from …/emsdk/emscripten/master/tools/optimizer/parser.cpp:2:
In file included from …/emsdk/emscripten/master/tools/optimizer/parser.h:12:
…/emsdk/emscripten/master/tools/optimizer/istring.h:3:10: fatal error:
'unordered_set' file not found
#include <unordered_set>
^
1 error generated.
I can reproduce that issue by launching the compiler from the command line. In parallel build mode, sometimes it's instead complaining about <cstdint> for optimizer.cpp instead. Both these headers exist in /opt/local/libexec/llvm-3.7/include/c++/v1/.
What's the canonical way to use the macports-installed version of clang++ including its headers? Do I have to use -I and work out the full path, or is there something shorter?
Can I safely do so without also switching the runtime library to the one shipped with MacPorts' clang? If not, can I somehow encode the full path of the runtime library into the created binary, either for that single library or using the -rpath argument to ld or some equivalent alternative?
Update: I get unresolved symbols when I try to link stuff after specifying the include directory manually, and I don't know how to solve that. The libcxx package from MacPorts is empty except for a readme file.
I've solved the original problem by adding CXXFLAGS=--stdlib=libc++ to the environment. Then even the system version of clang will do everything I need. That flag works magic for MacPorts' version of clang as well: specifying that I get a successful build, and I can even verify (using the -E compiler switch) that it's using the headers I mentioned before. I'm still not certain whether there is anything to ensure that the headers match the system's version of libc++, though.