我尝试使用通过 conan 安装的 gtest,但最终出现了未定义的引用链接器错误。这个问题或多或少是这个 stackoverflow 问题的后续。但我认为提供的例子很简单。我在最新的 arch linux x64 下编译,使用 gcc 6.3。
C++ 版本会不会有些不匹配?或者您对如何解决问题有任何其他想法吗?
我将在以下提供我的源代码:
目录树:
tree
.
??? CMakeLists.txt
??? conanfile.txt
??? main.cpp
Run Code Online (Sandbox Code Playgroud)
主.cpp:
#include <iostream>
#include <gtest/gtest.h>
class TestFixture : public ::testing::Test {
protected:
void SetUp(){
std::cout << "SetUp()" << std::endl;
}
void TearDown(){
std::cout << "TearDown()" << std::endl;
}
};
TEST_F (TestFixture, shouldCompile) {
std::cout << "shouldCompile" << std::endl;
ASSERT_TRUE(true); // works, maybe optimized out?
ASSERT_TRUE("hi" == "hallo"); // undefined reference
}
int main(int argc, …Run Code Online (Sandbox Code Playgroud) 我正在尝试在模板类中的 CUDA 内核中分配共享内存:
template<typename T, int Size>
struct SharedArray {
__device__ T* operator()(){
__shared__ T x[Size];
return x;
}
};
Run Code Online (Sandbox Code Playgroud)
只要没有相同类型和大小的共享内存被检索两次,这就会起作用。但是当我尝试获得相同类型和大小的两次共享内存时,第二个共享内存指向第一个:
__global__
void test() {
// Shared array
SharedArray<int, 5> sharedArray;
int* x0 = sharedArray();
int* y0 = sharedArray();
x0[0] = 1;
y0[0] = 0;
printf("%i %i\n\n", x0[0], y0[0]);
// Prints:
// 0 0
}
Run Code Online (Sandbox Code Playgroud)
一种解决方案是在每次调用共享内存类时添加一个 id,例如:
template<int ID, typename T, int Size>
struct StaticSharedArrayWithID {
__device__ static T* shared(){
__shared__ T x[Size];
return x;
}
};
Run Code Online (Sandbox Code Playgroud)
但是我必须提供一些计数器,它提供了一个非常丑陋的用户界面:
__global__
void …Run Code Online (Sandbox Code Playgroud) 我想遍历一个multimap(地图图),例如:map<int,map<char, string>>在boost hana的帮助下.lamba函数at不能采用引用类型&map(编译错误:非const引用),因此,我无法在multimap中加载或存储元素.
template <typename T_Map, typename T_Tuple>
auto& traverse(T_Map &map, T_Tuple &keys){
auto at = [](auto &map, auto key) -> auto& {
return map[key];
};
return hana::fold_left(keys, map, at);
}
Run Code Online (Sandbox Code Playgroud)
有可能像我一样用boost :: hana来解决这个问题吗?或者还有其他方式吗?
更新1:
以前的解决方案没有hana需要参数包.但我需要一个接受键作为元组的函数.
template <typename T_Map, typename T, typename... Ts>
auto& traverse(T_Map &map, T key, Ts... keys){
return traverse(map[key], keys...);
}
template <typename T_Map, typename T>
auto& traverse(T_Map& map, T key){
return map[key];
}
Run Code Online (Sandbox Code Playgroud) 我使用 nix 包管理器安装了 boost $ nix-env -i boost,但是在我的配置文件的当前一代中没有 boost 标头。
因此~/.nix-profile/include/boost不会退出,但可以在~/.nix-profile/lib.
我在 nix 商店中搜索并在商店boost-dev内的文件夹中找到了标题。
为什么 nix 不将 boost 头文件链接到我当前的一代?