0

How I can add a Some.lib file to my project in Code::Blocks 12.11 version?

I am tried to find linker options (Project, Building Options have a only Post/Prebuild steps, Custom Variables, "Make" commands). #pragma comment(lib, xxx.lib) - useless for GCC compiler, and the function from my lib file - SFileOpenFileEx(file, szArchivedFile, 0, &hFile) showed me the error: not declared (i.e. lib not working.)

How i can resolve this?

Source is:

#include "resourcemanager.h"
#include "filestream.h"

#include <physfs.h>
#include <archivelib> //mylib 

ResourceManager g_resources;

void ResourceManager::init(const char *argv0)
{
    PHYSFS_init(argv0);
    PHYSFS_permitSymbolicLinks(1);
}

void ResourceManager::terminate()
{
    PHYSFS_deinit();
}

//test function for library
bool ResourceManager::openArchive(const std::string& szArchiveName, const std::string& szArchivedFile, const std::string& szFileName)
{
    HANDLE hDat   = NULL;          // Open archive handle
    HANDLE hFile  = NULL;          // Archived file handle
    HANDLE handle = NULL;          // Disk file handle
    int    nError = ERROR_SUCCESS; // Result value

    //openArchive
    if(nError == ERROR_SUCCESS)
    {
        if(!SFileOpenArchive(szArchiveName, 0, 0, &hDat))
            nError = GetLastError();
    }

    if(nError == ERROR_SUCCESS)
    {
        if(!SFileOpenFileEx(hDat, szArchivedFile, 0, &hFile))
            nError = GetLastError();
    }

    //file opens, return true. just test.
    return true;
}

the error is Line: 340|error: ‘SFileOpenArchive’ was not declared in this scope

Happy Day
  • 297
  • 1
  • 5
  • 14
  • "Not declared" suggests you are missing an include rather than a library. What is the exact error message? What does the code look like? – Alan Stokes Aug 03 '14 at 10:58
  • added. SFileOpenArchive and SFileOpenFileEx is Library functions, but i dont have idea, how to make them work in Code::Blocks. In MSVS the solution is "pragma comment" but in this cause i dont have idea how to implement this – Happy Day Aug 03 '14 at 11:12

1 Answers1

1

That's a compilation error, not a link error, so the problem has nothing to do with libraries. You need to make a declaration of the function visible, which is normally done by including a header.

If the SFileOpenArchive you want is the one in StormLib (which would be useful information to include in the question) then the documentation clearly states that the header is StormLib.h, so you need to add

#include "StormLib.h"

to your program.

EDIT: If after that you have linking problems, see How do I link to a library with Code::Blocks?.

Community
  • 1
  • 1
Alan Stokes
  • 18,815
  • 3
  • 45
  • 64
  • thanks, ill check it. But theme about linking libs in Code::Blocks is outdated. And i am already add it, by Settings--->Compiler--->Linker Settings--->Add library. That actually works in 12.11ver – Happy Day Aug 03 '14 at 14:29