I started my study with OneAPI SYCL but I normally use QtCreator as my IDE. I did a HelloSYCL project with CMake and works fine in the terminal and in the VSCode with OneAPI Extension as well, but didn't work in the QtCreator.
Every time I want to use SYCL I need to start ONEAPI environment with ". /opt/intel/oneapi/setvars.sh", but I don't know how to do it with QtCreator
Here is the way I'm compile
mkdir build; cd build
cmake -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -G Ninja -S .. -DCMAKE_PREFIX_PATH="/opt/intel/oneapi/compiler/latest/linux/cmake/SYCL/" -DSYCL_INCLUDE_DIR=/opt/intel/oneapi/compiler/latest/linux/include/sycl -DSYCL_LIBRARY_DIR=/opt/intel/oneapi/compiler/latest/linux/lib
cmake_minimum_required(VERSION 3.22)
project(testSYCL LANGUAGES CXX)
if(UNIX)
set(CMAKE_C_COMPILER icx)
set(CMAKE_CXX_COMPILER dpcpp)
endif(UNIX)
list(APPEND CMAKE_MODULE_PATH "/opt/intel/oneapi/compiler/2021.4.0/linux/")
list(APPEND CMAKE_MODULE_PATH "/opt/intel/oneapi/compiler/2021.4.0/linux/cmake/SYCL/")
find_package(IntelDPCPP REQUIRED)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release" CACHE PATH "Build Type" FORCE)
endif()
add_executable(testSYCL main.cpp)
#include <iostream>
#include <iomanip>
#include <CL/sycl.hpp>
int main()
{
for ( const auto& plataform : sycl::platform::get_platforms() ) {
std::cout << "=========================================================\n";
std::cout << std::setw(25);
std::cout << plataform.get_info<sycl::info::platform::name>() << "\n";
std::cout << plataform.get_info<sycl::info::platform::vendor>() << "\n";
std::cout << "Plataform: " << plataform.get_info<sycl::info::platform::version>() << "\n";
for ( const auto& device : plataform.get_devices() ) {
std::cout << "Devices\n";
std::cout << "Name: " << device.get_info<sycl::info::device::name>() << "\n";
std::cout << "Max Compute Units: " << device.get_info<sycl::info::device::max_compute_units>() << "\n";
std::cout << "Max Work Group Size: " << device.get_info<sycl::info::device::max_work_group_size>() << "\n";
std::cout << "Max Clock Frequency: " << device.get_info<sycl::info::device::max_clock_frequency>() << " MHz \n";
}
}
}
QtCreator CMake Error
QtCreator Custom Compiler added
The answer depends on the contents of setvars.sh. I assume this is a simple script setting environment variables.
One way to mimic it in QtCreator is to define a custom kit.
Go to Tools/Options/Kits. Highlight any kit you use and press "clone". Then, add to it manually the necessary environment variables in the field "Environment". Use this kit for your SYCL projects. This will work if your problem is caused by a compiler error.
If the problem occurs while running a program inside QtCreator, look at build/running options:
There you'll easily find options for changing the runtime or compile-time environment
Related
I am building a MacOS c++ application in CMake that is a terminal program with a few associated libraries. I would like bundle the executable because customers are familiar with that. However, then opening the bundled .app the terminal will not open and the program disappears immediately even if I request input.
For example, the application main.cpp
#include <iostream>
int main()
{
int x;
std::cout << "Hello World!\n";
std::cin >> x;
std::cout << "You said " << x << "\n";
return 0;
}
can be made up with CMakeLists.txt file:
cmake_minimum_required(VERSION 3.4)
project(hello_world)
SET(CURRENT_TARGET hello)
add_executable(${CURRENT_TARGET} MACOSX_BUNDLE main.cpp)
But if I double-click the hello.app file it creates, it closes immediately. Is there a way to fix this?
I have set up a cmake project using visual studio 2019. I want to start the debug session with some command line parameters.
To achieve that, I've configured the CMakeLists.txt with the VS_DEBUGGER_COMMAND_ARGUMENTS:
set( VS_DEBUGGER_COMMAND_ARGUMENTS "this" "is" "a" "test" )
set( VS_DEBUGGER_WORKING_DIRECTORY "." )
The first thing my C++ code do is to print out that parameters:
if (argc > 1) {
// config_file = argv[1];
for (std::size_t i = 0; i < argc; i++) {
std::cout << "argument " << i << ": " << argv[i] << std::endl;
}
}
else {
std::cout << "the value of argc is: " << argc << std::endl;
}
The problem is that when I run Debug, the output I've always see is the value of argc is 1. I've also tried to modify the launch.vs.json file as appears in this related question:
Adding command line arguments to project
and it doesn't work. Any ideas?
I'm trying to set up c++11 to my project on visual studio, and to find out which version the compiler used by default I used the following code:
#include <iostream>
int main(){
#if __cplusplus==201402L
std::cout << "C++14" << std::endl;
#elif __cplusplus==201103L
std::cout << "C++11" << std::endl;
#elif __cplusplus==199711L
std::cout << "C++" << std::endl;
#elif __cplusplus==201703L
std::cout << "C++17" << std::endl;
#elif __cplusplus==1
std::cout << "C+" << std::endl;
#endif
int* i = nullptr;
return 0;
}
Having output c++ (98) I tried to force the compiler to use c++11 via the CMakeLists like this:
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
The output was always C ++ (98), so I added
int* i = nullptr;
and amazingly the output remains c++ (98) but the application works without problems. How is this "anomaly" explained and how do I know / decide which standard to use?
According to this question: Visual Studio 2012 __cplusplus and C++ 11 , provided by #paddy, this is a known bug with MSVC in that the version macro is set to C++98. You should compile with the /Zc:__cplusplus switch to change the version macro to the correct value.
I need to install OpenMP on my Mac and use it in CLion. I re-installed gcc, confirmed I have it, /usr/bin/local/gcc-7. Do not understand if this comes with OpenMP or if I need to install something extra.
CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
project(lab_3)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
add_executable(lab_3 main.cpp)
main.cpp
#include <iostream>
#include <omp.h>
int main() {
#pragma omp parallel for
for (int i=0; i<10; i++) {
std::cout << "This is thread #" << omp_get_thread_num() << std::endl;
}
return 0;
}
Error message:
clang: error: unsupported option '-fopenmp'
community,
I have the following problem with building and using the Log4cplus library with Embarcadero.
First, I download the library from http://sourceforge.net/p/log4cplus/wiki/Home/, then I navigate to a Directory where I want to build my library, and type cmake -G "Borland Makefiles" mypathtotherootomypreviousdownload. It then says, the build files have been written to the current directory.
Now I start the MSYS sh.exe and type make. This does also work. I get a bin Folder with various working tests (as exe files) of the library. In this bin folder there is also a dll log4cplusUD.dll. Now I also find in a src folder the corresponding LIB log4cplusUD.lib.
I am of course familiar how you can statically link a dynamic library with Embarcadero. But on attempting to compile
#pragma hdrstop
#pragma argsused
#ifdef _WIN32
#include <tchar.h>
#else
typedef char _TCHAR;
#define _tmain main
#endif
#include <stdio.h>
#include "log4cplus/logger.h"
#include "log4cplus/consoleappender.h"
#include "log4cplus/loglevel.h"
#include <log4cplus/loggingmacros.h>
#include <iomanip>
using namespace std;
using namespace log4cplus;
int _tmain(int argc, _TCHAR* argv[])
{
log4cplus::initialize ();
SharedAppenderPtr append_1(new ConsoleAppender());
append_1->setName(LOG4CPLUS_TEXT("First"));
Logger::getRoot().addAppender(append_1);
Logger root = Logger::getRoot();
Logger test = Logger::getInstance(LOG4CPLUS_TEXT("test"));
LOG4CPLUS_DEBUG(root,
"This is"
<< " a reall"
<< "y long message." << endl
<< "Just testing it out" << endl
<< "What do you think?");
test.setLogLevel(NOT_SET_LOG_LEVEL);
LOG4CPLUS_DEBUG(test, "This is a bool: " << true);
LOG4CPLUS_INFO(test, "This is a char: " << 'x');
LOG4CPLUS_INFO(test, "This is a short: " << static_cast<short>(-100));
LOG4CPLUS_INFO(test, "This is a unsigned short: "
<< static_cast<unsigned short>(100));
LOG4CPLUS_INFO(test, "This is a int: " << 1000);
LOG4CPLUS_INFO(test, "This is a unsigned int: " << 1000u);
LOG4CPLUS_INFO(test, "This is a long(hex): " << hex << 100000000l);
LOG4CPLUS_INFO(test, "This is a unsigned long: " << 100000000ul);
LOG4CPLUS_WARN(test, "This is a float: " << 1.2345f);
LOG4CPLUS_ERROR(test,
"This is a double: "
<< setprecision(15)
<< 1.2345234234);
LOG4CPLUS_FATAL(test,
"This is a long double: "
<< setprecision(15)
<< 123452342342.25L);
LOG4CPLUS_WARN(test, "The following message is empty:");
LOG4CPLUS_WARN(test, "");
return 0;
}
I get a linker error,
not resolved external Symbol log4cplus::Logger::getInstance.
The code above is just one of the tests that compiled and run well, when running make from sh.exe.
So what am I doing wrong?
I also tried to link the above main.cpp againts log4cplusUD.lib with the following CMakeLists.txt file
cmake_minimum_required (VERSION 2.6)
project (log4cplustest)
include_directories("C:/Users/fin/Software/log4cplus-1.2.0-rc3/log4cplus-1.2.0-rc3/include")
add_executable(log4cplustest main.cpp)
target_link_libraries(log4cplustest log4cplusUD)
but I get the same Linker error!