gpt4 book ai didi

c++ - 将 sdl 与 g++ 链接时出现错误

转载 作者:行者123 更新时间:2023-11-28 05:13:46 24 4
gpt4 key购买 nike

我知道很多人都遇到过这样的问题,但是没有一个解决方案在我链接到 SDL 时有效,我的代码如下:

#include <SDL/SDL.h>
#include <iostream>

int main()
{
return 0;
}

我使用命令行 g++ 继承命令:

g++ main.cpp -o application -Wall -Ideps/include -Ldeps/lib -lSDL2 -lSDL2main

我在:

C:\users\user\desktop\my_stuff\code\visual_studio_code\c++\graphics

图形有:

deps
include
SDL
GL
lib
libs
main.cpp

我使用 -v 获取此输出:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.5.2/lto- wrapper.exe
Target: mingw32
Configured with: ../../src/gcc-4.5.2/configure --build=mingw32 --enable- languages=c,c++,ada,fort
ran,objc,obj-c++ --enable-threads=win32 --enable-libgomp --enable-lto -- enable-fully-dynamic-string --enable-libstdcxx-debug --enable-version-specific- runtime-libs --with- gnu-ld --disable-nls
--disable-win32-registry --disable-symvers --disable-werror -- prefix=/mingw32tdm --with-local-pr
efix=/mingw32tdm --enable-cxx-flags='-fno-function-sections -fno-data- sections' --with-pkgversio
n=tdm-1 --enable-sjlj-exceptions --with-bugurl=http://tdm- gcc.tdragon.net/bugs
Thread model: win32
gcc version 4.5.2 (tdm-1)
COLLECT_GCC_OPTIONS='-v' '-o' 'application.exe' '-Wall' '-Ideps/include' '- Ldeps/lib' '-mtune=i3
86' '-march=i386'
c:/mingw/bin/../libexec/gcc/mingw32/4.5.2/cc1plus.exe -quiet -v - Ideps/include -iprefix c:\ming
w\bin\../lib/gcc/mingw32/4.5.2/ main.cpp -quiet -dumpbase main.cpp - mtune=i386 -march=i386 -auxb
ase main -Wall -version -o C:\Users\Dad\AppData\Local\Temp\ccGn7cDz.s
GNU C++ (tdm-1) version 4.5.2 (mingw32)
compiled by GNU C version 4.5.2, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory"c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.5.2/include/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.5.2/include/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.5.2/include/c++/backward"

ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.5.2/../../../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.5.2/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.5.2/include-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.5.2/../../../../mingw32
/include"
#include "..." search starts here:
#include <...> search starts here:
deps/include
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/include/c++
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/include/c++/mingw32
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/include/c++/backward
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/include
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/include-fixed
End of search list.
GNU C++ (tdm-1) version 4.5.2 (mingw32)
compiled by GNU C version 4.5.2, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: c87e8bfb7b6e930a996a4301ffec06cc
COLLECT_GCC_OPTIONS='-v' '-o' 'application.exe' '-Wall' '-Ideps/include' '- Ldeps/lib' '-mtune=i3
86' '-march=i386'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/as.exe -o C:\Users\Dad\AppData\Lo
cal\Temp\ccqmlCUw.o C:\Users\Dad\AppData\Local\Temp\ccGn7cDz.s
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.5.2/;c:/mingw/bin/../libexec /gcc/;c:/mingw/b
in/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.5.2/;c:/mingw/bin/../lib/gcc/;c:/ mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/lib/;c:/mingw/bin/../lib/ gcc/mingw32/4.5.2/../../../
COLLECT_GCC_OPTIONS='-v' '-o' 'application.exe' '-Wall' '-Ideps/include' '- Ldeps/lib' '-mtune=i3
86' '-march=i386'
c:/mingw/bin/../libexec/gcc/mingw32/4.5.2/collect2.exe -Bdynamic -o application.exe c:/mingw/bi
n/../lib/gcc/mingw32/4.5.2/../../../crt2.o c:/mingw/bin/../lib/gcc/mingw32/4.5.2/crtbegin.o -Lde
ps/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.5.2 -Lc:/mingw/bin/../lib/gcc - Lc:/mingw/bin/../lib/g
cc/mingw32/4.5.2/../../../../mingw32/lib - Lc:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../.. C:\Use
rs\Dad\AppData\Local\Temp\ccqmlCUw.o -lSDL2 -lSDL2main -Bstatic -lstdc++ - Bdynamic -lmingw32 -lg
cc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 - lmingw32 -lgcc -lmold
name -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc/mingw32/4.5.2/crtend.o
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libmingw32.a(main.o): In function `main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `WinMain@16'
collect2: ld returned 1 exit status

我正在尝试设置 Visual Studio 代码以正确编译 C++。

我也知道我可以使用代码块或 visual studio 2015 或其他东西,但我有两个理由不这样做。1. 我与 4 个有时 5 个其他人共享这台计算机,硬盘已满,visual studio 至少为 4GB2. 我也有点想知道怎么做

最佳答案

试试这个:

Under Visual C++, you need to link with SDL2main.lib. Under the gcc build environments including Dev-C++, you need to link with the output of "sdl-config --libs", which is usually: -lmingw32 -lSDL2main -lSDL2 -mwindows

Source: SDL Doc

关于c++ - 将 sdl 与 g++ 链接时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43070351/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com