我在cygwin下遇到了cmake的问题.我安装了cygwin的CMake软件包和普通的CMake软件包(在windows中),每次运行CMake配置项目时都会显示以下信息:
$ CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:/home/LordEvil/build/CMakeFiles/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is: …Run Code Online (Sandbox Code Playgroud) 我目前正在重写一个非常古老的mmorpg的服务器端,我正在寻找一个好的开源网络库与C/C++一起使用.
由于客户端已经存在,我不能使用任何强制执行某种数据包结构或通信的库(例如,RakNet).
服务器将主要在三个不同的端口上使用UDP.
在网上搜索后,我发现了boost :: asio和libuv.
boost :: asio看起来像是一个成熟的选项,因为我已经使用了boost,但是我读到他们的UDP实现有点差,而且由于使用了一些锁定它无法实现多核处理器的最大性能epoll的.
libuv似乎很棒,是事件驱动的,由一个大项目支持,但目前没有这样的项目使用它,所以我对使用它有疑问.
你觉得怎么样?我可以在这样的项目中使用libuv,还是我必须使用boost :: asio?我也对其他建议持开放态度(他们需要跨平台,我已经放弃了enet,libevent和libev).
我有以下示例代码:
#include <functional>
#include <iostream>
#include <string>
void f(std::function<const std::string&()> fn) {
std::cout << "in f" << std::endl;
std::cout << "str: " << fn() << std::endl;
}
int main() {
std::string str = "a";
auto fn1 = [&]() { return str; };
auto fn2 = [&]() { const std::string& str2 = str; return str2; };
auto fn3 = [&]() -> const std::string& { return str; };
std::cout << "in main" << std::endl;
std::cout << "fn1: " << fn1() << std::endl; …Run Code Online (Sandbox Code Playgroud) 我有一个可变参数模板函数,我想用它有条件地向另一个可变参数模板函数添加参数。这是一个最小的例子,但我无法编译它:
// Copyright 2019 Google LLC.
// SPDX-License-Identifier: Apache-2.0
#include <utility>
template<typename... Args>
void f(Args&&... args) {
// does something with args
}
template<typename T, typename... Args>
void g(T&& t, int i, Args&&... args) {
if (i != 0) t(i, std::forward<Args>(args)...);
else t(std::forward<Args>(args)...);
}
int main() {
g(f, 0, 0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上述代码的 clang 输出为:
main.cpp:15:7: error: no matching function for call
to 'g'
g(f, 0, 0);
^
main.cpp:9:10: note: candidate template ignored:
couldn't infer template argument 'T'
void …Run Code Online (Sandbox Code Playgroud) 我想在我的程序中使用以下数据集合:
boost::unordered_set<boost::shared_ptr<Entity> > _entities;
Run Code Online (Sandbox Code Playgroud)
我正在使用unordered_set,因为我希望快速插入和删除(通过键,而不是迭代器)实体.
我怀疑的是,如果我实现以下两个功能:
void addEntity(boost::shared_ptr<Entity> entity) {
_entities.insert(entity);
}
void removeEntity(boost::shared_ptr<Entity> entity) {
_entities.remove(entity);
}
Run Code Online (Sandbox Code Playgroud)
当我尝试删除实体时,unordered_set会找到它吗?因为存储在unordered_set中的shared_ptr是我试图用来从unordered_set中删除实体的shared_ptr的副本,如果我调用removeEntity()的话.
我需要为unordered_set找到实体做什么?我是否需要创建一个比较函数来检查shared_ptr的值?但是,unordered_set不会因为散列函数使用shared_ptr作为散列而减速吗?我是否需要创建一个使用实体作为哈希的哈希函数?
c++ ×5
boost ×2
boost-asio ×1
c ×1
c++11 ×1
cmake ×1
cygwin ×1
lambda ×1
libuv ×1
shared-ptr ×1