参考サイト(Qiita)のライブラリパスをコマンドラインオプションで指定する場合という場所に乗せられている提示コード
gcc -o sample -L/usr/local/lib/hoge -lfoo -lbar main.c
ですが、これはコマンドプロンプトでは提示画像のようなディレクトリ構造の場合どうしたらいいのでしょうか?
自分はg++を使うので g++ -Lライブラリを探すディレクトリ -lライブラリ名 -lライブラリ名 ファイル名.cpp ファイル名cpp
としていますが、これが間違えているのでしょうか?
提示画像は参照先であるSDLライブラリのlib/x64/の中の.lib.dll系の場所
ソースとヘッダーはtestディレクトリにheaderとsourceという名前でディレクトリ分けしてあります。以前間違えたときそのディレクトリには#include ○○がありませんよ教えてくれたのでinclude パスは通っているはず。
g++ -L../SDL2/lib/x64/ -lSDL2 -lSDL2_ttf Game.cpp main.cpp
C:\Users\ユーザー名\Desktop\test\source>g++ -L../SDL2/lib/x64/-lSDL2-lSDL2_ttf main.cpp Game.cpp
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x48): undefined reference to `TTF_Init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x8e): undefined reference to `TTF_OpenFont'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0xa3): undefined reference to `SDL_GetError'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0xc1): undefined reference to `SDL_Init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0xcf): undefined reference to `SDL_GetError'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0xdf): undefined reference to `SDL_Log'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x11d): undefined reference to `SDL_CreateWindow'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x130): undefined reference to `SDL_GetError'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x140): undefined reference to `SDL_Log'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x167): undefined reference to `SDL_CreateRenderer'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x17c): undefined reference to `SDL_GetError'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x18c): undefined reference to `SDL_Log'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x240): undefined reference to `SDL_PollEvent'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x269): undefined reference to `SDL_GetKeyboardState'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x2e2): undefined reference to `SDL_GetTicks'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x31e): undefined reference to `SDL_GetTicks'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x5ba): undefined reference to `SDL_SetRenderDrawColor'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x5c8): undefined reference to `SDL_RenderClear'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x5dc): undefined reference to `TTF_OpenFont'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x610): undefined reference to `SDL_SetRenderDrawColor'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x641): undefined reference to `SDL_RenderFillRect'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x65d): undefined reference to `SDL_RenderFillRect'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x68e): undefined reference to `SDL_RenderFillRect'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x71f): undefined reference to `SDL_RenderFillRect'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x7b8): undefined reference to `SDL_RenderFillRect'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x808): undefined reference to `TTF_RenderUTF8_Blended'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x826): undefined reference to `SDL_CreateTextureFromSurface'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x85a): undefined reference to `SDL_SetRenderDrawColor'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x886): undefined reference to `SDL_QueryTexture'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x90a): undefined reference to `SDL_RenderCopy'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x918): undefined reference to `SDL_RenderPresent'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x926): undefined reference to `SDL_FreeSurface'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x934): undefined reference to `SDL_DestroyTexture'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x942): undefined reference to `TTF_CloseFont'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x95d): undefined reference to `SDL_DestroyRenderer'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x96a): undefined reference to `SDL_DestroyWindow'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\MATSUZ~1\AppData\Local\Temp\ccd88skb.o:Game.cpp:(.text+0x96f): undefined reference to `SDL_Quit'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
環境 Windows 10