i'm trying to build a simple cmake application to test the coverage functionality offer by clang in windows (in linux all work ok).
Environment is:
Clang version in use: 7.0
And using LLVM toolset with Visual Studio 2017 build tools
cmake 3.12 with ninja generator
What I'm doing is simple:
CMakeLists.txt
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
project(test)
add_compile_options(--coverage)
add_executable(${PROJECT_NAME}
main.cpp
)
the main.cpp is as simple as it can get:
#include <iostream>
#include <string>
int main(int argc, char const *argv[]) {
std::cout << "\ndone.\n";
return 0;
}
using the build tools environments vcvarsall.bat i initialize the environement to run and compile with clang, like that:
mkdir build
cd build
cmake -GNinja -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_LINKER=lld-link ..
cmake --build .
and the following errors hapear:
lld-link.exe: error: undefined symbol: __llvm_profile_runtime
>>> referenced by src\app\CMakeFiles\app.dir\main.cpp.obj:(__llvm_profile_runtime_user)
lld-link.exe: error: undefined symbol: __llvm_profile_register_function
>>> referenced by src\app\CMakeFiles\app.dir\main.cpp.obj:(__llvm_profile_register_functions)
>>> referenced by src\app\CMakeFiles\app.dir\main.cpp.obj:(__llvm_profile_register_functions)
What i'm doing wrong or what i need to link to?
Thanks
Update: with Fred input I realized what library I should be linking to, and if I add the following:
link_libraries("C:/Program Files/LLVM/lib/clang/7.0.0/lib/windows/clang_rt.profile-x86_64.lib")
everything works... but is this really the solution for my problem?
According to these Notes and Notes and simple example and another example you need to do this differently.
target_compile_options(${PROJECT_NAME} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
target_link_libraries(${PROJECT_NAME} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
I haven't tested the syntax or anything.
From what I gather is that --coverage is an older flag of making gcov compatible data. The LLVM documents give an example of -fprofile-instr-generate -fcoverage-mapping at compile and link command there is no documentation of --coverage. One of the examples say you need to link with --coverage the other example says you need to link with -fprofile-instr-generate -fcoverage-mapping and it will link in the profile libraries as needed.
Related
I'm trying to write some code using the boost libraries on windows 10. To build the application I have chosen mingw64, which I have installed together with MSYS2.
After downloading and installing the boost libraries(1.76), I tried this example code (https://www.boost.org/doc/libs/1_76_0/more/getting_started/windows.html#build-a-simple-program-using-boost), which I built fine using this command:
g++ .\example.cpp -o test.exe -IC:\Users\Benelli\BoostLib\boost_1_76_0\boost_1_76_0
This example works on my system so I assumed that the boost libraries are installed correctly, although I did not build them, but I understood that the boost.test libary can be used as "header only".
I written a simple code following this tutorial:https://www.boost.org/doc/libs/1_76_0/more/getting_started/windows.html#build-a-simple-program-using-boost.
#define BOOST_TEST_MODULE const_string test
#include <boost/test/unit_test.hpp>
This code does not compile and I really do not get why. Is the boost.test library really "header_only"?
The command I used to build it was:
g++ .\boost_test_example.cpp -o boost_test.exe -IC:\Users\Benelli\BoostLib\boost_1_76_0\boost_1_76_0
Which gives this error message:
For the header only:
I think you need to use boost/test/included/unit_test.hpp as per the boost docs at https://www.boost.org/doc/libs/1_69_0/libs/test/doc/html/boost_test/adv_scenarios/single_header_customizations/multiple_translation_units.html
I had a similar winMain error and had to the define for BOOST_TEST_DYN_LINK to the top of the code (when i was linking against the libraries).
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE const_string test
#include <boost/test/unit_test.hpp>
When not using the header only for the undefined references link with the boost test library, eg -LC:/msys64/mingw64/lib -lboost_unit_test_framework-mt.
I'm trying to compile libcxxabi with cmake, and running into issues. I believe that this is because I don't have a separate copy of llvm installed that has llvm-config. So I've checked out llvm, and am trying to build that with cmake. I get the error:
CMake Error at cmake/modules/HandleLLVMOptions.cmake:37 (message):
Host Clang must be able to find libstdc++4.7 or newer!
And cmake/modules/HandleLLVMOptions.cmake:37 is literally a block like:
check_cxx_source_compiles("
#include <atomic>
std::atomic<float> x(0.0f);
int main() { return (float)x; }"
LLVM_NO_OLD_LIBSTDCXX)
if(NOT LLVM_NO_OLD_LIBSTDCXX)
message(FATAL_ERROR "Host Clang must be able to find libstdc++4.7 or newer!")
endif()
and if I try to compile the 3 liner with the compiler flag -std=c++0x (which is higher up in the cmake file) I get the error:
atomic.cpp:1:10: fatal error: 'atomic' file not found
#include <atomic>
^
1 error generated.
How is it that I don't have support for c++11 atomics? I'm running OSX 10.8.5, upgraded from 10.8.4, and XCode version 5.1.1, and clang++ 5.1 (clang-503.0.40) (based on LLVM 3.4svn). I have no options to upgrade xcode in the app store, nor the developer tools. Do I need to reinstall XCode, or upgrade to Mavericks?
I needed to check out all of LLVM and pass an additonal command line argument to CMake.
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd ../projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
cd ..
mkdir build
cd build
cmake .. -DLLVM_ENABLE_LIBCXX=ON
make
make install
Had the same issue with xCode 6.4. When using atomic in a simple helloWorld program it worked, but when using a project generated by CMake, I had the "#error is not implemented"
It appears CMake needs special flags to enable c++11 on mac... So, did exactly (almost... replaced if(UNIX) by if(APPLE)) as kitware indicates here:
https://cmake.org/Wiki/CMake/Tutorials/C%2B%2B11Flags
In case the link stops working one day....
cmake_minimum_required(VERSION 2.6)
PROJECT(Test)
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")
endif()
# MSVC does not require any special flags
I have this minimal example:
QT -= gui
CONFIG += qt console
SOURCES += main.cpp
#include <QDebug>
int main(int argc, char** argv)
{
return 0;
}
which gives this link error when building the project:
c:/qtsdk/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: final link failed: Invalid argument
The link command looks like this:
g++ -Wl -Wl -Wl,-subsystem,console -mthreads -o debug\test.exe debug/main.o -L"c:\QtSDK\Desktop\Qt\4.8.1\mingw\lib" -lQtCored4
My setup:
Windows XP SP3
Qt SDK version 1.2.1 (QtCreator 2.4.1, Qt Desktop version 4.8.1) (fresh install at C:\QtSDK\)
MinGW32 version 4.4.0 (included in Qt SDK at C:\QtSDK\mingw\)
If I remove the #include <QDebug>, it compiles fine. If I include some other Qt header file, like for example QCoreApplication, it compiles fine, too.
EDIT: Here is a very strange minimal example. Consider an empty main function like above. Now if i put these includes, it fails to link:
#include <QWidget>
#include <QVariant>
But if I remove one of them, it links without an error.
What's the problem? Why doesn't mingw tell me what the invalid argument is?
Im wondering is the linker could not find the lQtCored4 lib? Is it actually in the -L directory?
For a week I've been struggling with compiling openCV programs. I've tried everything I could possibly find on the internet.
What I did is: I've downloaded OpenCV-2.3.1-win-superpack.exe and followed this official installation guide.
In the CMake (gui) my source was: D:\opencv and build destination was: C:\opencv.
I've also added C:\opencv\install\bin;C:\opencv\bin to my system's PATH variable.
What I want is to compile openCV programs on my Windows OS using MinGW's gcc/g++ compilers.
I've tried various gcc/g++ parameters that I've found on the internet and days playing with the -I and -L options the compiler can never find the openCV functions or structures.
What I am trying to compile:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char *argv[])
{
// Nothing but create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvWaitKey(0);
return 0;
}
Error:
Input:
gcc test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"
Output:
...\ccK4MfHv.o:test.c:(.text+0xa0b): undefined reference to `cvFree_'
Or with g++:
Input:
g++ test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"
Output:
...\ccXCTKa1.o:test.c:(.text+0x1e): undefined reference to `cvNamedWindow'
Side note: trying to compile in VS2005 I get the same error.
Thank you for your time!
In case someone else needs to solve this issue, here's how I got the posted OpenCV/HighGUI sample code to compile in Windows 7 x64 using MinGW, MSYS, and CMake:
build OpenCV from source using MinGW/MSYS/CMake. This is because I could not get the MinGW compiled version in the OpenCV-win-SuperPack to link properly in MinGW/MSYS/Windows 7 x64.
For full reference, here's how I compiled OpenCV:
make sure you have an up-to-date CMake (v2.6 or later) and MinGW (with GCC, G++, and MSYS options) installed
if you want the new Qt-based OpenCV HighGUI front-end, you will need to install Qt 4 (SDK).
download a OpenCV source/superpack version 2.2 or later (I used OpenCV-2.3.1-win-superpack.exe)
unzip the contents to [OPENCV_SOURCE_DIR] (I put it in C:/opencv, so there should be a file at C:/opencv/README for example)
create a [OPENCV_BUILD_DIR] directory elsewhere (I used C:/opencv/build/mingw)
use the CMake-GUI tool, specify the source directory as [OPENCV_SOURCE_DIR], the build directory as [OPENCV_BUILD_DIR], and click "Configure".
you may wish/need to go tweak the options (e.g. I ticked "Qt" and "Qt-OpenGL" entries, then clicked "Configure" again, then had to provide the path to the qmake executable)
once you have finished configuring OpenCV, click "Generate"
in a MSYS terminal, browse to [OPENCV_BUILD_DIR], and run "make" to build the code (this may take a while)
once the has been built properly, run "make install", which collects the built code/libraries/include dirs into [OPENCV_BUILD_DIR]/install folder (or a different folder if you changed the corresponding option when using the CMake-GUI tool)
add [OPENCV_BUILD_DIR]/install/bin folder to the PATH environmental variable. If you do not know how to do this, then I'd recommend using the Path Editor GUI tool.
if you end up using Qt, you will also need to put the bin folder of Qt SDK in the PATH environmental variable. This is the folder that includes qmake.exe.
put the following sample code into a file called test.c. I modified the includes slightly to make them compatible with OpenCV v2.2 and above.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
int main(int argc, char *argv[])
{
// Nothing but create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvWaitKey(0);
return 0;
}
in a MSYS terminal, browse to the folder where you put test.c, and run:
gcc -o test -I"[OPENCV_BUILD_DIR]/install/include" test.c \
-L"[OPENCV_BUILD_DIR]/install/lib" \
-lopencv_core[OPENCV_VERSION] \
-lopencv_imgproc[OPENCV_VERSION] \
-lopencv_highgui[OPENCV_VERSION]
So in my case:
gcc -o test -I"/c/opencv/build/mingw/install/include" test.c \
-L"/c/opencv/build/mingw/install/lib" \
-lopencv_core231
-lopencv_imgproc231
-lopencv_highgui231
Path Editor: http://www.redfernplace.com/software-projects/patheditor/
You have the directory, C:\opencv\install\bin, to locate libraries on the gcc/g++ command line, but I think you'll also need to specify the libraries to use as linker inputs as well. I'm not sure what libraries are part of the OpenCV distribution, but going by the example on the instruction page you linked to, one might be:
-lopencv_calib3d220.dll
You'll probably have to add one or more other ones (that follow the name pattern lib*.a in the C:\opencv\install\bin directory - or maybe some other lib directory that you should be passing in a -L option).
Good day!
Let us have a source file main.cpp and a CMakeLists.txt file containing the next text:
cmake_minimum_required(VERSION 2.6)
project(tmp)
set(CMAKE_CXX_FLAGS "-Wall")
add_executable(tmp.elf main.cpp)
Let's say the main.cpp file contains a simple "Hello, World!" program:
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
We can build the project with cmake CMakeLists.txt && make. Then we'll just get the tmp.elf file which we can just run. Or we can get no tmp.elf file and assume that something is wrong with the main.cpp source file (assuming the compiler and cmake are installed properly on the building system).
So, the question is: how can we do the same on the Windows machine? E.g. we will get the tmp.vcproj file after running cmake CMakeLists.txt and then we need to build it somehow. How the build process can be performed using command-line? (Java's Process.start(), actually :-P )
You can start the build in a platform and CMake generator independent fashion by invoking cmake with the --build option:
cmake --build .
For multi-configuration generators, you can specify the configuration in the following way:
cmake --build . --config Release
Also see the documentation.