编译时未检测到主要功能
main function not being detected when compiled
我正在尝试运行一个打开窗口的程序。目的是让程序开始打开一个窗口是所有程序的开始是正确的吗?
但是,当我出于某种原因运行代码时,我会遇到此错误:
Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
但是,在我的代码中,我确实具有main()
函数,所以为什么要遇到此错误?
这是我的代码:
#include <SDL2/SDL.h>
#include <SDL2_image/SDL_image.h>
#include <SDL2_ttf/SDL_ttf.h>
#include <stdio.h>
int main(){
if(SDL_Init( SDL_INIT_EVERYTHING ) < 0){
std::cout << "error 1n";
std::cout << SDL_GetError();
std::cout << "n";
return -1;
}
if(TTF_Init() < 0){
std::cout << "error 2n";
std::cout << TTF_GetError();
std::cout << "n";
return -1;
}
SDL_Window* window = SDL_CreateWindow("test", 0, 0, 500, 500, 0);
if(!window){
std::cout << "error 3n";
std::cout << SDL_GetError();
std::cout << "n";
return -1;
}
int windowid = SDL_GetWindowID(window);
SDL_Renderer* Renderer = SDL_CreateRenderer(window, -1, 0);
running = true;
SDL_Event event;
while(running){
while(SDL_PollEvent(&event)){
if(event.type == SDL_WindowEvent){
if(event.window.windowID == windowid){
if(event.window.type == SDL_WindowClose){
Destroywindow(window);
running = false;
}
}
}
}
}
return 0;
}
我的制作文件看起来像这样:
#!/bin/bash
brew update
brew install sdl2
g++ -o /Users/mikahshattuck/noneproject/none2019-05-0909-22-
14:2:/none.app/Contents/MacOS/mainrun.cpp -I /Library/Frameworks -l
SDL2
exit 0
这是完整的:
Already up-to-date.
Warning: sdl2 2.0.9_1 is already installed and up-to-date
To reinstall 2.0.9_1, run `brew reinstall sdl2`
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]
预先感谢您
在MACOS或Windows上使用SDL时,您需要将-Dmain=SDL_main
添加到编译标志中,并将-lSDL2main
添加到链接标志中。由于您正在使用Homebrew,因此您可以使其更容易,并且只需使用PKG-Config即可获得正确的标志。使用此编译器命令作为模板,并根据您的需求进行调整:
g $(pkg -config -cflags sdl2(-i/library/frameworks source.cpp -o output_executable $(pkg -config -libs sdl2(
但是,看来您还在使用SDL_TTF,而不仅仅是普通SDL。在这种情况下,您可能应该使用SDL2_ttf
而不是sdl2
作为PKG-Config的软件包参数:
g $(pkg -config -cflags sdl2_ttf(-i/library/frameworks source.cpp -o output_executable $(pkg -config -libs sdl2_ttf(
SDL2_TTF软件包取决于SDL2软件包,因此使用SDL2_TTF也将为SDL2发射所需的标志。
PKG-Config软件包的名称对应于由Homebrew安装到/usr/local/lib/pkgconfig
的*.pc
文件。
相关文章:
- 错误:在尝试检测 std::cout 是否<< t 时,功能强制转换为数组类型;有效
- "configure"脚本如何检测我的系统是否支持某些头文件或 cpp 功能?
- 检测功能失败static_assert成语
- 想要构建一些必要的库来检测功能.出现一些错误
- 如何在检测习惯用语中要求精确的功能签名?
- 编译时未检测到主要功能
- 如何检测功能是否存在
- 检测与SFINAE的协同依赖功能的模式
- 使用SFINAE检测编译时间是否存在过载的独立式功能
- 错误:OpenCV 3.4.0 CUDA ORB 功能检测
- 在编译时检测std :: size_t类型以调用正确的功能
- 该功能检测循环链接列表的时间复杂性是什么?
- 具有OPENCV的功能检测失败而seg故障
- C 如何检测何时将nullptr传递到预期std :: string的功能
- 如何通过编程检测电脑是否具有USB3功能
- 检测功能键被按下的最佳方法是什么
- 检测c++控制台中功能键
- 在OpenCV中使用GPU进行对象检测的HOG功能
- 迷宫功能无法检测已删除的墙
- 如何检测我的源代码中使用了哪些 C++11 功能