CMake: how to select a different shell - c++

Using CMake, how to choose the shell to be used? Mine seems to be set to sh by default, but I need some environment vars loaded from my .bashrc, and I guess changing the shell is the way to go.
I'm actually trying to set clang++ as the C++ compiler, with the following directive:
set (CMAKE_CXX_COMPILER "clang++")
But when I try to compile the code, the shell being used is sh, and it does not find clang++, as I make the binary visible via the following export, in my .bashrc:
export PATH="${PATH}:~/llvm/Debug+Asserts/bin/"
Here is the error, confirming sh cannot find the clang++ binary:
$ make
[100%] Building CXX object CMakeFiles/floyd-warshall.dir/main.cpp.o
/bin/sh: 1: clang++: not found
make[2]: *** [CMakeFiles/floyd-warshall.dir/main.cpp.o] Error 127
make[1]: *** [CMakeFiles/floyd-warshall.dir/all] Error 2
make: *** [all] Error 2

You should not force the c++ compiler this way in your cmake file (at first I thought you were using a toolchain file). Remove that line and let CMake finds the compiler by itself. To use clang++ set some environment variables before calling cmake. Something like:
export CC=clang
export CXX=clang++
cmake /path/to/your/project
make

Related

Make error: emmake make results in error when trying to build libxml2, can't find libxml.so.2

My goal is to compile my C program to wasm with emscripten (which I installed via emsdk). It uses libxml2. I am following the steps outlined here https://github.com/kripken/xml.js/blob/master/script/libxml2 to build
libxml2 from source with the appropriate emscripten parameters.
When I run emmake make, I get the following warnings and errors:
...
CCLD libxml2.la
emcc: warning: linking a library with `-shared` will emit a static object file.
This is a form of emulation to support existing build systems.
If you want to build a runtime shared library use the SIDE_MODULE setting. [-Wemcc]
emcc: warning: ignoring unsupported linker flag: `--version-script=./libxml2.syms` [-Wlinkflags]
wasm-ld: error: cannot open libxml2.so.2: No such file or directory
emcc: error: '/home/willy/emsdk/upstream/bin/wasm-ld -o .libs/libxml2.so.2.9.9 .libs/SAX.o .libs/entities.o .libs/encoding.o -L/home/willy/emsdk/upstream/emscripten/system/local/lib .libs/error.o -L/home/willy/emsdk/upstream/emscripten/system/lib .libs/parserInternals.o -L/home/willy/emsdk/upstream/emscripten/cache/wasm .libs/parser.o .libs/tree.o .libs/hash.o .libs/list.o .libs/xmlIO.o .libs/xmlmemory.o .libs/uri.o .libs/valid.o .libs/xlink.o .libs/HTMLparser.o .libs/HTMLtree.o .libs/debugXML.o .libs/xpath.o .libs/xpointer.o .libs/xinclude.o .libs/nanohttp.o .libs/nanoftp.o .libs/catalog.o .libs/globals.o .libs/threads.o .libs/c14n.o .libs/xmlstring.o .libs/buf.o .libs/xmlregexp.o .libs/xmlschemas.o .libs/xmlschemastypes.o .libs/xmlunicode.o .libs/xmlreader.o .libs/relaxng.o .libs/dict.o .libs/SAX2.o .libs/xmlwriter.o .libs/legacy.o .libs/chvalid.o .libs/pattern.o .libs/xmlsave.o .libs/xmlmodule.o .libs/schematron.o .libs/xzlib.o /home/willy/emsdk/upstream/emscripten/cache/wasm/libc.a libxml2.so.2 --relocatable -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr' failed (1)
make[2]: *** [Makefile:1065: libxml2.la] Error 1
make[2]: Leaving directory '/home/willy/CWasmSandbox/libxml2-2.9.9'
make[1]: *** [Makefile:1484: all-recursive] Error 1
make[1]: Leaving directory '/home/willy/CWasmSandbox/libxml2-2.9.9'
make: *** [Makefile:897: all] Error 2
The only thing I can gather with my limited understanding of emscripten is that it tries to access libxml2.so.2 which under normal circumstances would be generated from libxml2.la. But libxml2.so.2 was not generated because emscripten does not produce shared objects. Is this assesment correct? I tried passing the option CFLAGS="-s SIDE_MODULE=1" to make, but it didn't fix the error and was probably a stupid idea born from my limited knowledge of build systems. I also tried copying libxml2.so.2 from a previous installation into the appropriate directory, but no luck, and also kind of dumb since emscripten would have no use for .so files? What should my next steps be?
Easiest way is to resign from shared lib.
There is an important limitation with shared one (side module): it will not work if you are going to use threads in your main application.
So just make a change of ./script/libxml2
-emconfigure ../libxml2/configure --with-http=no --with-ftp=no --with-python=no --with-threads=no
+emconfigure ../libxml2/configure --with-http=no --with-ftp=no --with-python=no --with-threads=no --enable-shared=no
Build and link ./build/.libs/libxml2.a with your main application.

Building OpenCV 3.3 using Mingw-make gives error 2 at 47%

When trying to build OpenCV 3.3.0 with the mingw compiler I keep getting an error. First I am using CMake to generate the build files (I choose Mingw makefiles and select the gcc en g++ compilers myself, although using the native compilers gives me the same error at the exact same time). When I then use mingw32-make to build OpenCV I get the following error around 48%:
48%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/mathfuncs_core.avx.cpp.obj
[ 48%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/convert.avx2.cpp.obj
[ 48%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/mathfuncs_core.avx2.cpp.obj
[ 48%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/stat.avx2.cpp.obj
[ 48%] Building RC object modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj
C:\Qt\Tools\mingw530_32\bin\windres.exe: unknown option -- W
Usage: C:\Qt\Tools\mingw530_32\bin\windres.exe [option(s)] [input-file] [output-file]
The options are:
-i --input=<file> Name input file
-o --output=<file> Name output file
-J --input-format=<format> Specify input format
-O --output-format=<format> Specify output format
-F --target=<target> Specify COFF target
--preprocessor=<program> Program to use to preprocess rc file
--preprocessor-arg=<arg> Additional preprocessor argument
-I --include-dir=<dir> Include directory when preprocessing rc file
-D --define <sym>[=<val>] Define SYM when preprocessing rc file
-U --undefine <sym> Undefine SYM when preprocessing rc file
-v --verbose Verbose - tells you what it's doing
-c --codepage=<codepage> Specify default codepage
-l --language=<val> Set language when reading rc file
--use-temp-file Use a temporary file instead of popen to read
the preprocessor output
--no-use-temp-file Use popen (default)
-r Ignored for compatibility with rc
#<file> Read options from <file>
-h --help Print this help message
-V --version Print version information
FORMAT is one of rc, res, or coff, and is deduced from the file name
extension if not specified. A single file name is an input file.
No input-file is stdin, default rc. No output-file is stdout, default rc.
C:\Qt\Tools\mingw530_32\bin\windres.exe: supported targets: pe-i386 pei-i386 elf32-i386 elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex
modules\core\CMakeFiles\opencv_core.dir\build.make:1641: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj' failed
mingw32-make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj] Error 1
mingw32-make[2]: *** Waiting for unfinished jobs....
CMakeFiles\Makefile2:1550: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed
mingw32-make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
Makefile:159: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
I am quite the novice when it comes to building a library and for some reason building them always seems to fail with me. Can anyone help me?
-
Martijn
Maybe this answer can help. Its a problem with cmake and precompiled headers
try this : in cmake uncheck ENABLE_PRECOMPILED_HEADERS
If unchecking ENABLE_PRECOMPILED_HEADERS doesn't work. Try this:
Add a new entry to CMake
Name the entry: OPENCV_ALLOCATOR_STATS_COUNTER_TYPE with Value(String): int64_t
Configure and generate the MAKEFILE
Go to the build directory and execute make install or mingw32-make install
If you want more info of your compilation log, you can run make install VERBOSE=1

Cmake errors: The CXX Compiler identification is unknown, The C compiler identification is unknown

I'm trying to install OpenCV on Fedora 21 with a cross compiler for ARM processor.
However, when i try to configure using Cmake 3.03, it gives the error:
*The CXX compiler identification is unknown
The C compiler identification is unknown
Check for working CXX compiler: /opt/FriendlyARM/toolschain/4.5.1/bin/arm-linux-g++
Check for working CXX compiler: /opt/FriendlyARM/toolschain/4.5.1/bin/arm-linux-g++ -- broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCXXCompiler.cmake:54 (message):
The C++ compiler "/opt/FriendlyARM/toolschain/4.5.1/bin/arm-linux-g++" is
not able to compile a simple test program.
It fails with the following output:
Change Dir: /opt/opencv/relarm/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTryCompileExec1616328985/fast"
/usr/bin/gmake -f CMakeFiles/cmTryCompileExec1616328985.dir/build.make
CMakeFiles/cmTryCompileExec1616328985.dir/build
gmake[1]: Entering directory '/opt/opencv/relarm/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report
/opt/opencv/relarm/CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object
CMakeFiles/cmTryCompileExec1616328985.dir/testCXXCompiler.cxx.o
/opt/FriendlyARM/toolschain/4.5.1/bin/arm-linux-g++ -o
CMakeFiles/cmTryCompileExec1616328985.dir/testCXXCompiler.cxx.o -c
/opt/opencv/relarm/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
/opt/FriendlyARM/toolschain/4.5.1/lib/gcc/arm-none-linux-gnueabi/4.5.1/../../../../arm-none-linux-gnueabi/bin/as:
error while loading shared libraries: libz.so.1: cannot open shared object
file: No such file or directory
CMakeFiles/cmTryCompileExec1616328985.dir/build.make:57: recipe for target
'CMakeFiles/cmTryCompileExec1616328985.dir/testCXXCompiler.cxx.o' failed
gmake[1]: Leaving directory '/opt/opencv/relarm/CMakeFiles/CMakeTmp'
gmake[1]: ***
[CMakeFiles/cmTryCompileExec1616328985.dir/testCXXCompiler.cxx.o] Error 1
Makefile:118: recipe for target 'cmTryCompileExec1616328985/fast' failed
gmake: *** [cmTryCompileExec1616328985/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:63 (project)
Configuring incomplete, errors occurred!
See also "/opt/opencv/relarm/CMakeFiles/CMakeOutput.log".
See also "/opt/opencv/relarm/CMakeFiles/CMakeError.log".*
I tried adding Path to my bash_profile, so that it looks like this:
# .bash_profile
# Get the aliases and functions if [ -f ~/.bashrc ]; then
. ~/.bashrc fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin export PATH=$PATH:/usr/local/bin:/usr/local/sbin:/opt/FriendlyARM/toolschain/4.5.1/bin/arm-linux-g++:/usr/bin/gmake:/usr/share/bin:/usr/share/sbin
I Have been googling around for hours but couldn't find any helpful steps. Any help would be appreciated.
Thanks in advance.
From the output it appears that cmake was able to find your cross compiler but as the output says it can't compile a simple program. I would start with creating Hello World in C++ and trying to compile that with your cross compiler. If that doesn't work that is your first problem. If it does work then I would guess it has to do with some environment variable(s). You could try to have cmake print the environment variables before it tries to compile the simple C++ program and compare to your shell environment variables, sorry I can't be more helpful than that.
Update:
So I downloaded FriendlyArm and the binaries it provides are 32 bit ELF's so you will need the 32 bit version of libz. A yum install zlib.i686 should solve your issue. The FriendlyArm toolchain works for me and I have zlib.i686 installed already. If you get any other errors about missing shared objects make sure you have the 32 bit version installed.

Can someone explain why my cmake file fails to build my cpp file?

So I've got the following CMakeLists.txt file to try and build my main.cpp file.
project(shell)
set(extra_flags = -std=c++11 -Werror -Wall -Wextra)
set(CMAKE_CXX_FLAGS $(CMAKE_CXX_FLAGS) $(extra_flags))
add_executable(shell main.cpp)
At this point, I am just trying to build it with a Hello World program just to make sure everything works. But the flags are there for the rest of the program that I need to write. The actual process of calling cmake . works just fine, but when I use make I get the following error:
[100%] Building CXX object CMakeFiles/shell.dir/main.cpp.o
c++: fatal error: no input files
compilation terminated.
/bin/sh: 1: -o: not found
CMakeFiles/shell.dir/build.make:54: recipe for target 'CMakeFiles/shell.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/shell.dir/main.cpp.o] Error 127
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/shell.dir/all' failed
make[1]: *** [CMakeFiles/shell.dir/all] Error 2
Makefile:72: recipe for target 'all' failed
make: *** [all] Error 2
I'm new to Ubuntu and the command line, so any help would be greatly appreciated.
Make sure you use curly brackets ${} (comment above)
Make sure you delete your CMakeCache.txt if you want a "reset" (comment above)
I also developed the habit to always use set(CMAKE_CXX_FLGAS "${CMAKE_CXX_FLAGS} ${extra_flags}") instead of set(CMAKE_CXX_FLGAS ${CMAKE_CXX_FLAGS} ${extra_flags}) which proved to cause less headache in any of my applications. Try that as well.
Use make VERBOSE=1 to see which commands CMake actually runs. You then can mess with the command directly and see how you get it to work.
If it's just HelloWorld!, try leaving out the -std=c++11 flag (or any flags, really) and see.

Installing netcdf on Ubuntu 12.04

I have to use a recent version of gfortran and use netcdf. So I have to complie the netcdf libraries with this new version of gfortran, which is 4.8.2
Before configuration and installing of netcdf, I had to set the following environment variables:
#!/bin/bash
export CC="$HOME/gcc-trunk/bin/gcc"
export LDFLAGS="-L$HOME/gcc-trunk/lib -L$HOME/gcc-trunk/lib64"
export CPP="$HOME/gcc-trunk/bin/cpp"
export FC="$HOME/gcc-trunk/bin/gfortran"
export F77="$HOME/gcc-trunk/bin/gfortran -x f77"
export CXX="$HOME/gcc-trunk/bin/c++"
export CXXPP="$HOME/gcc-trunk/bin/cpp"
export LD_LIBRARY_PATH=$PWD/netcdf/lib:${LD_LIBRARY_PATH}
export CPPFLAGS="-DgFortran -cpp -I$PWD/netcdf/include"
export LDFLAGS="-L$PWD/netcdf/lib"
Everything goes ok when I run configure, but when I make "make check". I get the following error:
libtool: link: /home/antonio/gcc-trunk/bin/gfortran -x f77 -I../fortran -I../f90 -g -o .libs/nf_test test_get.o test_put.o nf_error.o nf_test.o test_read.o test_write.o util.o fortlib.o -L/media/022f8e40-437e-4c37-a8b0-538c07b842a3/home/antonio/DATOS/seas_pred/Fortran_code/netcdf/netcdf-fortran-4.2/netcdf/lib ../fortran/.libs/libnetcdff.so -lnetcdf -rpath /media/022f8e40-437e-4c37-a8b0-538c07b842a3/home/antonio/DATOS/seas_pred/Fortran_code/netcdf/netcdf/lib
gfortran: error: unrecognized command line option '-rpath'
make[2]: *** [nf_test] Error 1
make[2]: se sale del directorio «/media/022f8e40-437e-4c37-a8b0-538c07b842a3/home/antonio/DATOS/seas_pred/Fortran_code/netcdf/netcdf-fortran-4.2/nf_test»
make[1]: *** [check-am] Error 2
make[1]: se sale del directorio «/media/022f8e40-437e-4c37-a8b0-538c07b842a3/home/antonio/DATOS/seas_pred/Fortran_code/netcdf/netcdf-fortran-4.2/nf_test»
make: *** [check-recursive] Error 1
It seems -rpath is an option to be passed to the linker, so it should add a -Wl, before, but it doesn't.
Perhaps I should add this option in an environmental variable, but don't know which.
Can anybody help?
Thanks a lot.
I think you are compiling from the wrong directory. You have $PWD in the value field of LD_LIBRARY_PATH, CPPFLAGS & LDFLAGS. Easiest way to fix is to replace $PWD with the absolute path where your netcdf directory is located.
The problem was caused by the environmental variable F77.
It seems that configure, sets the appropriate values when this variable is not set, but get into trouble when we set it.
I solved it deleting the line in the script that sets the F77 variable.
Thaks to everybody who tired to find a solution, specially to Sadiq Huq.