I've tried to essentially build the PhysFS library with Cmake, what I used was Code::Blocks mingw makefiles. I can import in my project, I can technically declare the PhysFS_init() function (although that gives me too few arguments error) yet when I add an argument it tells me PHYSFS_init is an undefined reference.
That sounds so silly to me, how can you recognize it when it has no argument, but pretend it doesn't exist when I add an argument? I've run CMake twice, but I'm simply getting this:
[...]\src\main.cpp|20|undefined reference to `PHYSFS_init'|
The code, if necessary (just a bit, the rest is irrelevant):
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include "Globals.h"
#include "GameStates.h"
#include "GameWindow.h"
#include "GameMenu.h"
#include <physfs.h>
int main(int argc, char** argv)
{
///<|===================| Classes & Declarations |===================|>
sf::Event ev;
sf::RenderWindow winMain ( sf::VideoMode( WindowWidth, WindowHeight, 32 ), WindowTitle );
sf::Image Icon;
GameStates gameState;
GameMenu TitleMenu;
MenuButton buttons[4];
PHYSFS_init(NULL);
Why is this happening? What do I have to do to be able to use PhysFS in my project? I've built the library with CMake, I included the library I need, and I tried to initialize PhysFS which gave me an error which makes me feel like the way C++ compiles program is plain silly.
This is a general explanation of how C++ libraries work:
PHYSFS probably consists of header files and a static/dynamic library. The header file is where all the functions/classes of the library are declared, but not defined. Thus, when you include the header file into your project, your compiler can now know that the functions you call in the library exist, and exactly what type of parameters they take etc.
So to use a library, you must include its header files, which means you must add its include directory to the project/cmakelists.txt.
#some similar path to this
include_directories( /path/to/PHYSFS/include)
Now, when you actually link the executable into a binary, these functions must be "resolved" so that the linker knows where they actually are, so that they can be called. This is called "linking" with the library.
So to use a library you must link its library files.
In cmake this is done as follows:
add_executable(myexe myexe.cpp)
#Add library directory paths here
link_directories( /path/to/PHYSFSlibs/)
#libPHYS.a or libPHYS.so if using gcc convention, libPHYS.lib if MSVC convention
#cmake allows us to use the name of the library, instead of the filename to be portable.
target_link_libraries(myexe PHYSFS)
I am not particularly familiar with PHYSFS, but if you compiled it as a library, you should have one of these files to link to.
undefined reference to `PHYSFS_init
This is a problem with "linking" and usually means you failed to link the library, or the library is missing the implementation of this function. Linking the library should fix this.
EDIT
I misread your question, and assumed you were using cmake with your project and linking to PHYSFS.
First you must separately build PHYSFS, which will produce a library file (.a,.so or .lib) depending on the platform/IDE, then you must link that library file in your C::B linker options.
To do this:
Go to Project->Build options. Click Linker Settings.
Image (from here):
Add the library.