我在编译使用glfw3库的程序时遇到问题.
我在尝试使用make编译时得到未定义引用的错误列表但是我的类被编译成.o文件,只创建了最终的可执行文件.
标准输出:
g++ -Wall -g -c main.cpp -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi
g++ -Wall -g -c error.cpp -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi
g++ -Wall -g -c sWindow.cpp -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi
g++ -Wall -g -o ecl main.o error.o sWindow.o -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi
Run Code Online (Sandbox Code Playgroud)
标准错误:
/usr/local/lib/libglfw3.a(context.c.o): In function `parseGLVersion':
context.c:(.text+0x53): undefined reference to `glGetString'
/usr/local/lib/libglfw3.a(context.c.o): In function `_glfwRefreshContextAttribs':
context.c:(.text+0x907): undefined reference to `glGetIntegerv'
context.c:(.text+0x98a): undefined reference …Run Code Online (Sandbox Code Playgroud) 今天我从源代码构建了 clang-tidy,我使用 clang++ 构建了它。构建完成后,我创建了一个指向可执行文件的符号链接,如下所示:
ln -s /path/to/build/bin/clang-tidy /usr/local/bin/clang-tidy
Run Code Online (Sandbox Code Playgroud)
然后我尝试在简单的项目(包含打印 helloworld 代码的单个 .cpp 文件)上使用带有 cmake 的 clang-tidy。这是我的 cmake 文件的样子:
project(Test)
cmake_minimum_required(VERSION 3.12.0 FATAL_ERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_CXX_STANDARD 17)
set(CXX_STANDARD_REQUIRED)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_CLANG_TIDY
clang-tidy;
-checks=*;)
add_executable(Test
helloworld.cpp)
Run Code Online (Sandbox Code Playgroud)
我在某处读到 cmake 的整洁仅适用于 Unix Makefiles & Ninja 生成器(或可能其他一些)。我通常使用 xcode 生成器,但我对这两个不太熟悉,所以我并不真正关心其他人。我已经尝试使用 Unix Makefiles 和 Ninja 生成和构建项目,但是我得到了这个错误:
/Users/xxxxxxx/Dev/VSCodePlayground/helloworld.cpp:2:10: error: 'string' file not found [clang-diagnostic-error]
Run Code Online (Sandbox Code Playgroud)
我找到了一些信息,这可能是因为 clang 找不到 libc++/stdlib 头文件。因此,我尝试了带-v参数的建议编译(成功而没有错误),并在包含目录中获得了此输出:
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现简单的网络游戏(客户端-服务器),它使用 UDP 通过网络传输游戏事件,并且我运行良好,但现在我想在同一控制台应用程序中通过 tcp 添加游戏聊天。我尝试使用select()非阻塞主套接字来实现多客户端聊天。聊天作为独立应用程序运行,但我在将其组合在一起时遇到问题。
基本上我的服务器循环如下所示:
while(true)
{
sendUDPdata()
...
while(true)
{
receiveUDPdata()
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我想将聊天添加到服务器的主循环(处理 UDP)时,如下所示:
while(true)
{
HandleTCPConnections();
sendUDPdata();
...
while(true)
{
receiveUDPdata();
}
}
Run Code Online (Sandbox Code Playgroud)
调用select()会 HandleTCPConnections()阻塞整个服务器。有什么办法可以处理这个问题吗?
我有一个简单的二维向量类,它实现为内联函数/运算符.
但是,当我想要实例化没有参数的Vector时,我得到Unresolved externals错误,我不知道为什么.但是,当我使用带参数的其他构造函数时,它没问题.
这是我的班级:
class Vector2
{
public:
float x;
float y;
public:
//Constructors
Vector2() : x(0.0f), y(0.0f) {}
Vector2(const float _x, const float _y) : x(_x), y(_y) { }
};
Run Code Online (Sandbox Code Playgroud)
创建导致错误的实例:
Vector2 a();
Run Code Online (Sandbox Code Playgroud)
但是当用其他构造函数实例化时,它没问题.这也有效:
Vector2 a = Vector2();
Run Code Online (Sandbox Code Playgroud)
我明白了:
1>main.obj : error LNK2019: unresolved external symbol "class GreenEye::Maths::Vector2 __cdecl a(void)" (?a@@YA?AVVector2@Maths@GreenEye@@XZ) referenced in function main
1>X:\Development\Projects\Engine\x64\Debug\Test.exe : fatal error LNK1120: 1 unresolved external
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢.