Bugster
Bugster

Reputation: 1594

Problems initializing PhysFS

I've tried to pack some assets into an archive with a custom extension, trying to follow a physfs tutorial (A very vague one) when I ran into a problem with initializing PHYSFS. It takes a paramater argv[0] however it's giving me an error that argv was not declared. I also tried passing argv as a paramater to the main function, but that doesn't seem to work either. Here's the small bit of code that's causing me trouble:

#include "physfs.h"

int FileManager()
{
  PHYSFS_init(argv[0]) //error
  ...
}

Upvotes: 0

Views: 1060

Answers (2)

Sion Sheevok
Sion Sheevok

Reputation: 4217

From looking at this tutorial, it seems that the first and only parameter to PHYSFS_init is supposed to be the path to the executing file. It also remarks that this is typically null, so you can pass null. I'd agree that the tutorial is lacking, in so far as I've read that paragraph, in that it doesn't actually explain what the parameter is used for. I assume it uses the parameter to calculate what the root directory to work from should be, based on the executable's path.

Upvotes: 1

Marc Cohen
Marc Cohen

Reputation: 3808

argv is not a globally scoped variable so it's not visible in FileManager(). argv is typically a parameter to main(). So in order for your FileManager function to see it, you'd want to define it as a parameter in both your main() and FileManager() function definitions and then pass argv when you call FileManager() (presumably from main).

If you don't call FileManager() from main, say you go through some intermediary function, just repeat the process - define argv as a param for the intermediate function and make sure it propagates argv in its call to FileManager() (extend this as needed per your call stack).

Upvotes: 3

Related Questions