Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Decrius on March 10, 2008, 09:35:29 pm

Title: Building other projects
Post by: Decrius on March 10, 2008, 09:35:29 pm
So, some projects do not provide plug'n'play files (pre-build library files) to work with (like ENet), so I have to build it myself. Often it gives me lots of errors because CodeBlocks is slightly different then VisualStudio (atleast, the compilers they use). This time not, so far...

What I get: Please select a host to "run" a library...
I searched on this forum, and someone said "go to this config window", and there I could choose a "host executable". What IS a host executable? What does it DO? And more important, which .exe should I choose, as its obviously not notepad.exe

I didn't got that to work, though it DID create a .a file, I put it in lib/ and linked to it in my project, getting lots of undefined reference errors, so I guess the .a file is not good =/

Any help on this one would be much appreciated :)
Decrius
Title: Re: Building other projects
Post by: Decrius on March 11, 2008, 06:46:51 pm
Nobody knows? How could this be so difficult/barely documentated anyways? It's quite important as most libraries don't come with the plug'n'play libraries.
Title: Re: Building other projects
Post by: dmoore on March 11, 2008, 07:28:26 pm
I have no idea what you mean by plug'n'play library (a self executing library?). Irrespective of IDE, you won't to be able to "run" or "debug" a library directly, but you can run or debug a program or process that calls into your library (and, if debugging, step through the library routines).

you should be able to link to any library binaries that you build (.dll/.a) without errors. try switching on compiler logging so that you can see the full command lines being passed to gcc. try those issuing those same commands at the command line yourself.

other people might be able to help if you provide more info on the errors and the project structure
Title: Re: Building other projects
Post by: Decrius on March 11, 2008, 09:13:58 pm
I did: I cannot build my own library files.

With plugnplay I mean: you put the libraries in a directory, link to them and you got it running. Some projects do not provide those libraries but only its sources, therefore I need to build it myself. "You need a host exectuable to "run" a library..." thats the error I get, even if I start my own library project =/.
Title: Re: Building other projects
Post by: Seronis on March 11, 2008, 11:23:51 pm
Well it means exactly what it says.  The project you appear (by my understanding) to be talking about creates a library and does not create a program.  So you cant execute it.  Which is normal behaviour as libraries are not executable on their own.  So build your library,  then create a project that -uses- the library.

Sorry if im misunderstanding your problem but this it what it seems you are talking about.
Title: Re: Building other projects
Post by: Decrius on March 12, 2008, 03:28:21 pm
Well it means exactly what it says.  The project you appear (by my understanding) to be talking about creates a library and does not create a program.  So you cant execute it.  Which is normal behaviour as libraries are not executable on their own.  So build your library,  then create a project that -uses- the library.

Sorry if im misunderstanding your problem but this it what it seems you are talking about.

Ah okay ^^. How easy, I never thought of that '-.-

Sorry then, thanks :)
Title: Re: Building other projects
Post by: Decrius on March 12, 2008, 09:19:18 pm
Okay, I tried to build my own, but I got the classic 'undefined reference to ... ' error.

Sources:
The static library:
Code
int add_it_now(int i1, int i2)
{
    return i1 + i2;
}

The executable:
Code
#include <iostream>

using namespace std;

int add_it_now(int, int);

int main()
{
    cout << add_it_now(5, 2) << endl;
    return 0;
}

In the executable's project I added the right search directory for the linker and added the static library to the list. What could I possibly do wrong here?

Thanks in advance
Title: Re: Building other projects
Post by: dmoore on March 12, 2008, 10:50:40 pm
try using the library name WITHOUT the file extension (.a, .lib or .dll)
Title: Re: Building other projects
Post by: Decrius on March 12, 2008, 11:04:27 pm
In the list I added it without .a and without lib infront...or do you mean the filename of the static library?

EDIT:
Whatever else I do it cannot find the library, using the method I'm used to (libtestlib.a should be added to the left list as testlib and to the right list as -ltestlib) it _can_ find the library. Should the library contain a header file?
Title: Re: Building other projects
Post by: mattsnowboard on March 13, 2008, 09:33:37 pm
I think you do need a header.  Though you did use
Code
int add_it_now(int, int);
so that should suffice