User forums > Using Code::Blocks
Create a static library
BlubBlub:
hey guys (:
I use the wizard for creating a static library.
In the main.c file there is a little sample which I compiled:
--- Code: ---int SampleAddInt(int i1, int i2)
{
return i1 + i2;
}
// A function doing nothing ;)
void SampleFunction1()
{
// insert code here
}
// A function always returning zero
int SampleFunction2()
{
// insert code here
return 0;
}
--- End code ---
I tried it and it worked ( I got a .a file ) But when I want to use it in a project like:
--- Code: ---#include <iostream>
using namespace std;
int main()
{
cout << SampleAddInt ( 12, 14 ) << endl ;
}
--- End code ---
I get an error:
--- Quote ---'SimpleAddInt' was not declared in this scope
--- End quote ---
I linked the .a file, but it didn“t work. :S
Can somebody help me ?
oBFusCATed:
Yes, read/learn what a header file is/does.
Jenna:
--- Quote from: oBFusCATed on February 09, 2010, 11:20:25 pm ---Yes, read/learn what a header file is/does.
--- End quote ---
And how to mix C and C++ sources/libs.
BlubBlub:
--- Quote from: oBFusCATed on February 09, 2010, 11:20:25 pm ---Yes, read/learn what a header file is/does.
--- End quote ---
I know what header files do.
--- Quote from: jens on February 09, 2010, 11:24:45 pm ---And how to mix C and C++ sources/libs.
--- End quote ---
Do you mean extern "C" ?
Can you be more specific ? :(
I have a guess:
--- Code: ---#ifndef MAIN_H
#define MAIN_H
extern "C"
int SampleAddInt(int, int ) ;
#endif
--- End code ---
It works, but is it that what you meant ?
Jenna:
--- Quote ---#ifdef __cplusplus
extern "C" {
#endif
--- End quote ---
at the top of the header and
--- Quote ---#ifdef __cplusplus
}
#endif
--- End quote ---
at the bottom.
So you can use the same header with C and C++-sources.
Navigation
[0] Message Index
[#] Next page
Go to full version