g++ can't find a certain function definition, even though it's clearly defined in a included library.
main.cpp
#include <StormLib.h>
int main()
{
HANDLE hMpq = NULL;
SFileOpenArchive("file_name", 0, MPQ_OPEN_READ_ONLY, &hMpq);
return 0;
}
StormLib.h
// ...
bool WINAPI SFileOpenArchive(const TCHAR * szMpqName, DWORD dwPriority, DWORD dwFlags, HANDLE * phMpq);
// ...
Compiling
$ g++ main.cpp
/usr/bin/ld: /tmp/ccNSvuaq.o: in function `main':
main.cpp:(.text+0x4b): undefined reference to `SFileOpenArchive'
collect2: error: ld returned 1 exit status
As you can see, SFileOpenArchive()
is clearly defined in StormLib.h
, and the header file is found by g++, but it still says SFileOpenArchive()
is not defined.
This seems to be a commonly asked question on StackOverflow, and most solutions tell me to include the library in the compile command. This is what I've tried:
$ g++ main.cpp /usr/local/include/StormLib.h
$ g++ -o test main.cpp /usr/local/include/StormLib.h
Both commands give the same error as the first.
The most similar question with an answer is this one with over 1400 votes, but it does not solve my problem.
I'm new to C++ so this likely has a simple solution.