将sdl与g ++链接时出错

时间:2017-03-28 13:02:55

标签: c++ g++ static-linking

我知道很多人都有这样的问题,但没有一个解决方案能够连接到SDL继承我的代码:

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

int main()
{
    return 0;
}

即时使用命令行g ++继承命令:

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

im in:

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个人分享这台电脑,硬盘正在填满,视觉工作室至少4GB 我也想知道如何做到这一点

1 个答案:

答案 0 :(得分:1)

试试这个:

  

在Visual C ++下,您需要链接SDL2main.lib。在包含Dev-C ++的gcc构建环境下,您需要链接&#34; sdl-config --libs&#34;的输出,通常是:-lmingw32 -lSDL2main -lSDL2 -mwindows

Source: SDL Doc