Hello,
This code will output two values, representing the address of a static variable. The two output values should be equal, but tested on the Nvidia, they are not equal. It is now expected that the problem lies in the cu cpp mixed compilation, but no relevant official samples have been found. Please also help locate the problem.
Thank you
The code is follows.
main1.cu:
#include "timer.h"
int main() {
Timer tm;
tm.f1();
tm.f2();
return 0;
}
main2.cpp:
#include "timer.h"
int f() {
Timer tm;
tm.f1();
// tm.f2();
return 0;
}
time.h:
#pragma once
#include <iostream>
static int TimerT;
class Timer {
public:
void f1() {
std::cout << (long)(&TimerT) << std::endl;
}
void f2() {
std::cout << (long)(&TimerT) << std::endl;
}
};
CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(main)
find_package(CUDA)
#set(CUDA_NVCC_FLAGS -O3)
cuda_add_executable(main main1.cu main2.cpp)