I am having issues with compiling my CUDA code with CMake. I am using CUDA 7 and the version information from nvcc is as follows:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2014 NVIDIA Corporation
Built on Tue_Dec__9_18:10:46_CST_2014
Cuda compilation tools, release 7.0, V7.0.17
My CMake file uses the find_cuda macro as follows:
find_package(CUDA)
if(CUDA_FOUND)
list(APPEND CUDA_NVCC_FLAGS "-arch=sm_20;--compiler-options;-std=c++11;-O2;-DVERBOSE")
endif(CUDA_FOUND)
I added the std=c++11 compiler flag after many posts suggested this was needed. However, I get exactly the same errors with or without this flag.
I also added the following to remove the C++11 support from nvcc compilation flags but this does not change anything either.
if(CMAKE_COMPILER_IS_GNUCC)
string(REPLACE "-std=c++11" "" CUDA_HOST_FLAGS "${CUDA_HOST_FLAGS}")
string(REPLACE "-std=c++0x" "" CUDA_HOST_FLAGS "${CUDA_HOST_FLAGS}")
endif(CMAKE_COMPILER_IS_GNUCC)
The errors I get are as follows:
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h(432): error: identifier "nullptr" is undefined
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h(432): error: expected
a ";"
/usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h(190): error:
expected a ";"
/usr/include/c++/4.8/exception(63): error: expected a ";"
/usr/include/c++/4.8/exception(68): error: expected a ";"
/usr/include/c++/4.8/exception(76): error: expected a ";"
/usr/include/c++/4.8/exception(83): error: expected a ";"
/usr/include/c++/4.8/exception(93): error: expected a "{"
/usr/include/c++/4.8/bits/exception_ptr.h(64): error: function
"std::current_exception" returns incomplete type
"std::__exception_ptr::exception_ptr"
I am using gcc 4.8 but get the same errors with 4.7 as well. I am on cmake 2.8.12.2.
Compiling with CMAKE verbose gives the following flags for nvcc compilation:
/usr/local/cuda-7.0/bin/nvcc /home/xargon/Dropbox/code/gpu-mosaicing
/src/gpu/kernels/bgra_2_gray.cu -c -o /home/xargon/code/mosaicing_bin
/gpu/kernels/CMakeFiles/kernels.dir//./kernels_generated_bgra_2_gray.cu.o
-ccbin /usr/bin/cc -m64 -DUSE_CUDA -DUSE_OPENCV -DUSE_QT -Xcompiler
,\"-std=c++11\",\"-O3\",\"-DNDEBUG\" -arch=sm_20 --compiler-options
-std=c++11 -O2 -DVERBOSE -DNVCC -I/usr/local/cuda-7.0/include -I/usr/local
/include/opencv -I/usr/local/include -I/home/xargon/Dropbox/code/gpu-
mosaicing/src/cpu/gui/qt -I/usr/include -I/home/xargon/Dropbox/code/gpu-
mosaicing/src/cpu/core -I/home/xargon/Dropbox/code/gpu-mosaicing/src/cpu
/datasources -I/home/xargon/Dropbox/code/gpu-mosaicing/src/gpu
/intraoperability -I/home/xargon/Dropbox/code/gpu-mosaicing/src/utils
-I/usr/local/cuda-7.0/include
This worked for me using CUDA 7, gcc 4.8.2 and CMake 3.0.2.
I updated the code and added a simple thrust-based example to make it clear that you can use C++11 in CUDA code
CMakeLists.txt
project(cpp11)
find_package(CUDA)
list(APPEND CUDA_NVCC_FLAGS "-arch=sm_20;-std=c++11;-O2;-DVERBOSE")
SET(CUDA_PROPAGATE_HOST_FLAGS OFF)
CUDA_ADD_EXECUTABLE(cpp11 main.cpp test.h test.cu)
test.h
#ifndef TEST_H
#define TEST_H
int run();
#endif
test.cu
#include "test.h"
#include <thrust/device_vector.h>
#include <thrust/reduce.h>
#include <thrust/sequence.h>
template<typename T>
struct Fun
{
__device__ T operator()(T t1, T t2)
{
auto result = t1+t2;
return result;
}
};
int run()
{
const int N = 100;
thrust::device_vector<int> vec(N);
thrust::sequence(vec.begin(),vec.end());
auto op = Fun<int>();
return thrust::reduce(vec.begin(),vec.end(),0,op);
}
main.cpp
#include <iostream>
#include "test.h"
int main()
{
std::cout << run() << std::endl;
return 0;
}
list(APPEND CUDA_NVCC_FLAGS "-std=c++11") is enough,SET(CUDA_PROPAGATE_HOST_FLAGS OFF) may be not necessary, and it cause me could not set breakpoint in .cu file
If stumbling across this question while searching for a way to compile Genoils CPP-Ethereum build for Ethereum CUDA mining, my problem was solved by editing the CMakeLists.txt file in the cpp-ethereum/libethash-cuda folder.
Where it states:
set(CUDA_NVCC_FLAGS
${CUDA_NVCC_FLAGS};
-gencode etc etc)
add "-std=c++11" after the semi-colon, as follows:
set(CUDA_NVCC_FLAGS
${CUDA_NVCC_FLAGS};
-std=c++11
-gencode etc etc)
Related
I am compiling a C++ code on mac using swig and making a shared .so library.
I have found a similar question here but I get an error for the last line:
ls
sl.i sl.hpp
swig -c++ -python sl.i
clang -O2 -fPIC -c sl_wrap.cxx -I /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8
clang -lpython -dynamiclib sl_wrap.o -o _sl.so
ls
sl.py sl_wrap.o sl.wrap.cxx sl.i sl.hpp
error:
ld: library not found for -lpython
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
My machine:
ProductName: macOS
ProductVersion: 13.0
Homebrew clang version 15.0.2
Target: x86_64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
SWIG Version 4.0.2
Compiled with clang++ [x86_64-apple-darwin21.1.0]
Configured options: +pcre
A toy example:
sl.hpp:
#include <cmath>
#include <string>
#include <iostream>
class My_Class
{
private:
int N;
public:
int add(int a, int b)
{
return (a+b);
}
};
sl.i:
%module sl
%{
#include "sl.hpp"
%}
%include stl.i
%include "std_string.i"
/* instantiate the required template specializations */
namespace std {
%template(IntVector) vector<int>;
%template(DoubleVector) vector<double>;
%template(DoubleVector2) vector<vector<double> >;
%template(SingleVector) vector<float>;
%template(SingleVector2) vector<vector<float> >;
}
%include "sl.hpp"
Install python via brew or
check your installation for python3-config tool, then launch e.g.
/opt/homebrew/bin/python3-config --ldflags
and set the output as linker flags to your cmdline, e.g.
-L/opt/homebrew/opt/python#3.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10/config-3.10-darwin -ldl -framework CoreFoundation
I have the following code (intended to detect if the compiler supports C++14):
#include <memory>
#include <algorithm>
// Check the version language macro, but skip MSVC because
// MSVC reports 199711 even in MSVC 2017.
#if __cplusplus < 201402L && !defined(_MSC_VER) && !defined(__INTEL_COMPILER)
#error "insufficient support for C++14"
#endif
int main()
{
auto ptr = std::make_unique<int>(42);
constexpr int max = std::max(0, 1);
(void) ptr;
(void) max;
return 0;
}
When compiling it with g++ (version 11.2.1) and the line g++ -std=c++14 test.cpp -o test it works fine. When compiling it with the intel compiler (version 2021.3.0 (gcc version 11.2.1 compatibility)) instead using icpc -std=c++14 test.cpp -o test, it fails with
In file included from /usr/include/c++/11/cwchar(44),
from /usr/include/c++/11/bits/postypes.h(40),
from /usr/include/c++/11/iosfwd(40),
from /usr/include/c++/11/bits/shared_ptr.h(52),
from /usr/include/c++/11/memory(77),
from test.cpp(1):
/usr/include/wchar.h(155): error: attribute "__malloc__" does not take arguments
__attribute_malloc__ __attr_dealloc_free;
^
In file included from /usr/include/c++/11/cstdlib(75),
from /usr/include/c++/11/bits/stl_algo.h(59),
from /usr/include/c++/11/algorithm(62),
from test.cpp(2):
/usr/include/stdlib.h(565): error: attribute "__malloc__" does not take arguments
__attr_dealloc_free;
^
In file included from /usr/include/c++/11/cstdlib(75),
from /usr/include/c++/11/bits/stl_algo.h(59),
from /usr/include/c++/11/algorithm(62),
from test.cpp(2):
/usr/include/stdlib.h(569): error: attribute "__malloc__" does not take arguments
__THROW __attr_dealloc (reallocarray, 1);
^
In file included from /usr/include/c++/11/cstdlib(75),
from /usr/include/c++/11/bits/stl_algo.h(59),
from /usr/include/c++/11/algorithm(62),
from test.cpp(2):
/usr/include/stdlib.h(797): error: attribute "__malloc__" does not take arguments
__attr_dealloc_free __wur;
^
compilation aborted for test.cpp (code 2)
What exactly is going wrong here, and how can I fix it?
Short update: Looks as if CUDA is running into similar issues, and it might be related to glibc 2.34: https://forums.developer.nvidia.com/t/cuda-11-5-samples-throw-multiple-error-attribute-malloc-does-not-take-arguments/192750/15
Compiling and executing the shared code using icpc 2021.4 and it runs fine.
Used below command to compile the code.
icpc -std=c++14
Below are the environment details.
Operating System: Ubuntu 18.04.3 LTS
Kernel: Linux 4.15.0-76-generic
For compatibility, Kindly refer the link for Intel® C++ Compiler Classic System Requirements
https://software.intel.com/content/www/us/en/develop/articles/oneapi-c-compiler-system-requirements.html
I am facing an error while I am trying to build my project using cmake.
I manually downloaded and install gtest on my pc (i.e. gtest header files are available in /usr/include) and libs such as gtest, gtest_main in /usr/lib)
Below is the code of my projects main function. (lte_softmodem_test.cpp)
#include <gtest/gtest.h>
#include <iostream>
using namespace std;
TEST(sample, sample2){
}
int main(int argc, char **argv)
{
cout << "This is test" << endl;
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
return 0;
}
When I compiled this file separately using the below command, it is working!!
g++ eNB_scheduler_test.cpp -L /usr/lib/ -lgtest -lgtest_main -pthread -std=c++11
But, when I tried to include this in my projects CMake file, it is showing me an error.
CMake file: (CMake file is a bit large, so I have just included few lines where I am trying to compile this file)
# lte-softmodem is both eNB and UE implementation
###################################################
add_executable(lte-softmodem
${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c
${OPENAIR_TARGETS}/RT/USER/lte-enb.c
${OPENAIR_TARGETS}/RT/USER/lte-ru.c
${OPENAIR_TARGETS}/RT/USER/ru_control.c
${OPENAIR_TARGETS}/RT/USER/lte-softmodem.c
${OPENAIR_TARGETS}/RT/USER/lte-softmodem_test.cpp
${OPENAIR_TARGETS}/RT/USER/lte-softmodem-common.c
${OPENAIR2_DIR}/ENB_APP/NB_IoT_interface.c
${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c
${OPENAIR_TARGETS}/COMMON/create_tasks.c
${OPENAIR_TARGETS}/COMMON/create_tasks_mbms.c
${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c
${OPENAIR2_DIR}/RRC/NAS/nas_config.c
${OPENAIR2_DIR}/RRC/NAS/rb_config.c
${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c
${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/multicast_link.c
${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/socket.c
${OPENAIR3_DIR}/NAS/UE/nas_ue_task.c
${OPENAIR_DIR}/common/utils/utils.c
${OPENAIR_DIR}/common/utils/system.c
${GTPU_need_ITTI}
${XFORMSINTERFACE_SOURCE}
${T_SOURCE}
${CONFIG_SOURCES}
${SHLIB_LOADER_SOURCES}
add_dependencies(lte-softmodem rrc_flag s1ap_flag x2_flag)
target_link_libraries (lte-softmodem
-Wl,--start-group
RRC_LIB S1AP_LIB S1AP_ENB F1AP_LIB F1AP M2AP_LIB M2AP_ENB X2AP_LIB X2AP_ENB M3AP_LIB M3AP_ENB GTPV1U SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT MME_APP UDP SCHED_LIB SCHED_RU_LIB PHY_COMMON PHY PHY_RU LFDS L2
${MSC_LIB} ${RAL_LIB} ${NAS_UE_LIB} ${ITTI_LIB} ${FLPT_MSG_LIB} ${ASYNC_IF_LIB} ${FLEXRAN_AGENT_LIB} ${FSPT_MSG_LIB} ${PROTO_AGENT_LIB} LFDS7
NFAPI_COMMON_LIB NFAPI_LIB NFAPI_VNF_LIB NFAPI_PNF_LIB NFAPI_USER_LIB
-Wl,--end-group z dl gtest gtest-main -lpthread)
CMake Output in verbose mode while compiling the file lte_softmodem_test.cpp:
/usr/bin/c++ -DASN1_MINIMUM_VERSION=924
-DCMAKE_BUILD_TYPE="RelWithDebInfo" -DDRIVER2013 -DENABLE_ITTI -DENABLE_NAS_UE_LOGGING -DENABLE_USE_CPU_EXECUTION_TIME -DENABLE_USE_MME -DENABLE_VCD -DENB_MODE -DEXMIMO_IOT -DF1AP_RELEASE=R15 -DF1AP_VERSION=3873 -DFIRMWARE_VERSION=""No svn information"" -DFLPT_VERSION=V2 -DFSPT_VERSION=V2 -DJUMBO_FRAME
-DLTE_RRC_VERSION=3696 -DM2AP_RELEASE=R14 -DM2AP_VERSION=3584 -DM3AP_RELEASE=R14 -DM3AP_VERSION=3584 -DMAX_NUM_CCs=1 -DNAS_BUILT_IN_UE -DNAS_UE -DNB_ANTENNAS_RX=2 -DNB_ANTENNAS_TX=4 -DNETTLE_VERSION_MAJOR=3 -DNETTLE_VERSION_MINOR=2 -DNO_RRM -DNUMBER_OF_UE_MAX_NB_IoT=16 -DNone=1 -DOAI_NW_DRIVER_USE_NETLINK -DOPENAIR2 -DOPENAIR_LTE -DPACKAGE_BUGREPORT="openair4g-devel#lists.eurecom.fr" -DPACKAGE_NAME="" -DPACKAGE_VERSION=""Branch: master Abrev. Hash: 9a06ceb Date: Wed Sep 9 16:15:50 2020 +0200"" -DPHYSIM -DPHY_CONTEXT
-DRel14=1 -DS1AP_RELEASE=R14 -DS1AP_VERSION=3664 -DTRACE_RLC_MUTEX -DT_TRACER -DX2AP_RELEASE=R14 -DX2AP_VERSION=3680 -I/root/openairinterface5g/cmake_targets/lte_build_oai/build/CMakeFiles/RRC_Rel14
-I/root/openairinterface5g/cmake_targets/lte_build_oai/build/CMakeFiles/S1AP_R14
-I/root/openairinterface5g/openair3/S1AP -I/root/openairinterface5g/cmake_targets/lte_build_oai/build/CMakeFiles/M2AP_R14
-I/root/openairinterface5g/openair2/M2AP -I/root/openairinterface5g/cmake_targets/lte_build_oai/build/CMakeFiles/M3AP_R14
-I/root/openairinterface5g/openair3/M3AP -I/root/openairinterface5g/cmake_targets/lte_build_oai/build/CMakeFiles/X2AP_R14
-I/root/openairinterface5g/openair2/X2AP -I/root/openairinterface5g/cmake_targets/lte_build_oai/build/CMakeFiles/F1AP_R15.2.1
-I/root/openairinterface5g/openair2/F1AP -I/root/openairinterface5g/targets/ARCH/USRP/USERSPACE/LIB -I/root/openairinterface5g/targets/ARCH/BLADERF/USERSPACE/LIB -I/root/openairinterface5g/targets/ARCH/LMSSDR/USERSPACE/LIB -I/root/openairinterface5g/targets/ARCH/ETHERNET/USERSPACE/LIB -I/root/openairinterface5g/targets/ARCH/IRIS/USERSPACE/LIB -I/root/openairinterface5g/targets/ARCH/COMMON -I/root/openairinterface5g/cmake_targets/lte_build_oai/build/CMakeFiles
-I/root/openairinterface5g/openair2/COMMON -I/root/openairinterface5g/openair2/UTIL -I/root/openairinterface5g/openair2/UTIL/LOG -I/root/openairinterface5g/openair3/COMMON -I/root/openairinterface5g/openair3/UTILS -I/root/openairinterface5g/nfapi/open-nFAPI/nfapi/public_inc -I/root/openairinterface5g/nfapi/open-nFAPI/common/public_inc -I/root/openairinterface5g/nfapi/open-nFAPI/pnf/public_inc -I/root/openairinterface5g/nfapi/open-nFAPI/nfapi/inc -I/root/openairinterface5g/nfapi/open-nFAPI/sim_common/inc -I/root/openairinterface5g/nfapi/open-nFAPI/pnf_sim/inc -I/root/openairinterface5g/openair1 -I/root/openairinterface5g/openair2 -I/root/openairinterface5g/openair3/NAS/TOOLS -I/root/openairinterface5g/openair2/ENB_APP -I/root/openairinterface5g/openair2/MCE_APP -I/root/openairinterface5g/openair2/LAYER2/RLC -I/root/openairinterface5g/openair2/LAYER2/RLC/AM_v9.3.0 -I/root/openairinterface5g/openair2/LAYER2/RLC/UM_v9.3.0 -I/root/openairinterface5g/openair2/LAYER2/RLC/TM_v9.3.0 -I/root/openairinterface5g/openair2/LAYER2/PDCP_v10.1.0 -I/root/openairinterface5g/openair2/RRC/LTE/MESSAGES -I/root/openairinterface5g/openair2/RRC/LTE -I/root/openairinterface5g/common/utils -I/root/openairinterface5g/common/utils/ocp_itti -I/root/openairinterface5g/openair3/NAS/COMMON -I/root/openairinterface5g/openair3/NAS/COMMON/API/NETWORK -I/root/openairinterface5g/openair3/NAS/COMMON/EMM/MSG -I/root/openairinterface5g/openair3/NAS/COMMON/ESM/MSG -I/root/openairinterface5g/openair3/NAS/UE/ESM -I/root/openairinterface5g/openair3/NAS/UE/EMM -I/root/openairinterface5g/openair3/NAS/UE/API/USER -I/root/openairinterface5g/openair3/NAS/COMMON/IES -I/root/openairinterface5g/openair3/NAS/COMMON/UTIL -I/root/openairinterface5g/openair3/SECU -I/root/openairinterface5g/openair3/SCTP -I/root/openairinterface5g/openair3/UDP -I/root/openairinterface5g/openair3/GTPV1-U -I/root/openairinterface5g/openair3/MME_APP -I/root/openairinterface5g/targets/COMMON -I/root/openairinterface5g/openair2/ENB_APP/CONTROL_MODULES/PHY -I/root/openairinterface5g/openair2/ENB_APP/CONTROL_MODULES/MAC -I/root/openairinterface5g/openair2/ENB_APP/CONTROL_MODULES/RRC -I/root/openairinterface5g/openair2/ENB_APP/CONTROL_MODULES/PDCP -I/root/openairinterface5g/openair2/UTIL/OSA -I/root/openairinterface5g/openair2/UTIL/LFDS/liblfds6.1.1/liblfds611/inc
-I/root/openairinterface5g/openair2/UTIL/LFDS/liblfds7.0.0/liblfds700/inc
-I/root/openairinterface5g/openair2/LAYER2/PROTO_AGENT -I/root/openairinterface5g/openair2/UTIL/MEM -I/root/openairinterface5g/openair2/UTIL/LISTS -I/root/openairinterface5g/openair2/UTIL/FIFO -I/root/openairinterface5g/openair2/UTIL/OCG -I/root/openairinterface5g/openair2/UTIL/MATH -I/root/openairinterface5g/openair2/UTIL/TIMER -I/root/openairinterface5g/openair2/UTIL/OMG -I/root/openairinterface5g/openair2/UTIL/OTG -I/root/openairinterface5g/openair2/UTIL/CLI -I/root/openairinterface5g/openair2/UTIL/OPT -I/root/openairinterface5g/openair2/UTIL/OMV -I/root/openairinterface5g/openair3/GTPV1-U/nw-gtpv1u/shared -I/root/openairinterface5g/openair3/GTPV1-U/nw-gtpv1u/include -I/root/openairinterface5g -I/root/openairinterface5g/cmake_targets/lte_build_oai/build/CMakeFiles/FLPT_V2
-I/root/openairinterface5g/openair2/UTIL/ASYNC_IF -I/root/openairinterface5g/cmake_targets/lte_build_oai/build/CMakeFiles/FSPT_V2
-I/root/openairinterface5g/common/utils/hashtable -I/root/openairinterface5g/common/utils/msc -I/root/openairinterface5g/nfapi/open-nFAPI/pnf/inc -I/root/openairinterface5g/nfapi/open-nFAPI/vnf/public_inc -I/root/openairinterface5g/nfapi/open-nFAPI/vnf/inc -I/root/openairinterface5g/nfapi/oai_integration -I/root/openairinterface5g/openair3/NAS/UE -I/root/openairinterface5g/openair3/NAS/UE/API/USIM -I/root/openairinterface5g/openair3/NAS/UE/EMM/SAP -I/root/openairinterface5g/openair3/NAS/UE/ESM/SAP -I/root/openairinterface5g/openair2/UTIL/LFDS/liblfds6.1.1/liblfds611/src
-I/root/openairinterface5g/openair2/UTIL/LFDS/liblfds7.0.0/liblfds700/src
-I/usr/include/libxml2 -I/usr/include/atlas -I/root/openairinterface5g/common/utils/T -mavx2 -msse4.1 -mssse3 -Wno-packed-bitfield-compat -fPIC -Wall -fno-strict-aliasing -rdynamic -std=c++11 -D'MAKE_VERSION(a,b,c)=((a)*256+(b)*16+c)' -O2 -g -DNDEBUG -o CMakeFiles/lte-softmodem.dir/root/openairinterface5g/targets/RT/USER/lte-softmodem_test.cpp.o
-c /root/openairinterface5g/targets/RT/USER/lte-softmodem_test.cpp
Error log:
<command-line>:0:6: error: expected identifier before numeric constant
<command-line>:0:6: error: expected unqualified-id before numeric constant
<command-line>:0:6: error: expected type-specifier before numeric constant
<command-line>:0:6: error: expected type-specifier before numeric constant
In file included from /usr/local/include/gtest/gtest.h:62:0,
from /root/openairinterface5g/targets/RT/USER/lte-softmodem_test.cpp:2:
/usr/local/include/gtest/internal/gtest-internal.h:690:39: error: variable or field ‘GenerateNamesRecursively’ declared void
void GenerateNamesRecursively(internal::None, std::vector<std::string>*, int) {}
^
<command-line>:0:6: error: expected unqualified-id before numeric constant
In file included from /usr/local/include/gtest/gtest.h:62:0,
from /root/openairinterface5g/targets/RT/USER/lte-softmodem_test.cpp:2:
/usr/local/include/gtest/internal/gtest-internal.h:690:71: error: expected primary-expression before ‘*’ token
void GenerateNamesRecursively(internal::None, std::vector<std::string>*, int) {}
^
/usr/local/include/gtest/internal/gtest-internal.h:690:72: error: expected primary-expression before ‘,’ token
void GenerateNamesRecursively(internal::None, std::vector<std::string>*, int) {}
^
/usr/local/include/gtest/internal/gtest-internal.h:690:74: error: expected primary-expression before ‘int’
void GenerateNamesRecursively(internal::None, std::vector<std::string>*, int) {}
^
/usr/local/include/gtest/internal/gtest-internal.h:757:61: error: template argument 3 is invalid
class TypeParameterizedTest<Fixture, TestSel, internal::None> {
^
/usr/local/include/gtest/internal/gtest-internal.h:815:64: error: wrong number of template arguments (2, should be 3)
class TypeParameterizedTestSuite<Fixture, internal::None, Types> {
^
/usr/local/include/gtest/internal/gtest-internal.h:778:7: note: provided for ‘template<template<class T> class Fixture, class Tests, class Types> class testing::internal::TypeParameterizedTestSuite’
class TypeParameterizedTestSuite {
Edit:
I have edited the question with the error logs, and MAKE output while compiling the file. Thanks in advance for spending your time.
This is how I personally include Google Test in a clean way:
# To prevent overriding the parent project's compiler/linker settings on Windows.
if(WIN32)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
SOURCE_DIR "${GOOGLETEST_DOWNLOAD_DIR}/src" # choose preferred directory
BINARY_DIR "${GOOGLETEST_DOWNLOAD_DIR}/bin"
)
FetchContent_MakeAvailable(googletest)
#gtest and gtest-main will be available here
You can also use the FindGTest.cmake module with the find_package function make sure to define the environment variable GTEST_ROOT. If these methods would work while your method does not, then it could be your linker settings through cmake(check for syntax errors).
I'm using c++ builder 10.2 with the clang compiler on Windows 10 pro. Can anyone tell me why this doesn't compile?
// crt_tzset.cpp
// This program uses _tzset to set the global variables
// named _daylight, _timezone, and _tzname. Since TZ is
// not being explicitly set, it uses the system time.
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
int main( void )
{
_tzset();
int daylight;
_get_daylight( &daylight );
printf( "_daylight = %d\n", daylight );
long timezone;
_get_timezone( &timezone );
printf( "_timezone = %ld\n", timezone );
size_t s;
char tzname[100];
_get_tzname( &s, tzname, sizeof(tzname), 0 );
printf( "_tzname[0] = %s\n", tzname );
exit( 0 );
}
I get 3 'Unresolved external' errors relating to _get_daylight, _get_timezone and _get_tzname.
Since I don't have "c++builder", I tried this with MinGW.
With a straightforward compile and link command like this:
gcc -Wall -Werror -pedantic -O2 tz.c -o tz
I got the same errors:
C:\Users\###\AppData\Local\Temp\ccI8j8Mj.o:tz.c:(.text.startup+0x1f): undefined reference to `__imp__get_daylight'
C:\Users\###\AppData\Local\Temp\ccI8j8Mj.o:tz.c:(.text.startup+0x3a): undefined reference to `__imp__get_timezone'
C:\Users\###\AppData\Local\Temp\ccI8j8Mj.o:tz.c:(.text.startup+0x61): undefined reference to `__imp__get_tzname'
collect2.exe: error: ld returned 1 exit status
A single grep revealed the library libucrtbase.a (among others) to contain the symbol _get_daylight. Adding this library to the command:
gcc -Wall -Werror -pedantic -O2 tz.c -lucrtbase -o tz
This produced a runnable program.
The other libraries are all libmsvcr*.a in different versions, I tried just one of them. This was successful, too.
Edit:
With a not-so-current "clang" I didn't even need to add the library.
clang -Wall -Werror -pedantic -O3 tz.c -o tz-clang.exe
This compiled and linked without any error and runs perfectly.
(clang version 7.0.1 (tags/RELEASE_701/final), Target: x86_64-pc-windows-msvc)
I compiled & installed gcc4.4 using macports.
When I try to compile using -> g++ -g -Wall -ansi -pthread -std=c++0x main.cpp...:
#include <thread>
...
std::thread t(handle);
t.join();
....
The compiler returns:
cserver.cpp: In member function 'int CServer::run()':
cserver.cpp:48: error: 'thread' is not a member of 'std'
cserver.cpp:48: error: expected ';' before 't'
cserver.cpp:49: error: 't' was not declared in this scope
But std::cout <<... compiles fine..
Can anyone help me?
gcc does not fully support std::thread yet:
http://gcc.gnu.org/projects/cxx0x.html
http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html
Use boost::thread in the meantime.
Edit
Although the following compiled and ran fine for me with gcc 4.4.3:
#include <thread>
#include <iostream>
struct F
{
void operator() () const
{
std::cout<<"Printing from another thread"<<std::endl;
}
};
int main()
{
F f;
std::thread t(f);
t.join();
return 0;
}
Compiled with
g++ -Wall -g -std=c++0x -pthread main.cpp
Output of a.out:
Printing from another thread
Can you provide the full code? Maybe there's some obscure issue lurking in those ...s?
I had the same issue on windows using MinGW. I found wrapper classes for in on github mingw-std-threads Including
mingw.mutex.h, mingw.thread.h files to global MinGW directory fixed this issue. All I had to do is to include header file and my code stayed the same
#include "mingw.thread.h"
...
std::thread t(handle);
...
Drop -ansi, it means -std=c++98, which you obviously don't want. It also causes macro __STRICT_ANSI__ to be defined and this may change the behavior of the headers, e.g. by disabling C++0x support.