User forums > General (but related to Code::Blocks)
static library [SOLVED]
sspecter:
Hi.
I am having a newbie problem with static library, but as i think it has not much to do with C::B i am posting here in general forum.
i am trying to find a way to use string in a static library (.c) but nothing that i try work.
thats the last thing im trying:
--- Code: ---#include "string.h"
using namespace std;
string SampleAddInt(int i1, int i2)
{
return i1 + i2;
}
--- End code ---
the error:
Syntax error before namespace.
I already tried to use std::string with no luck.
How can i use string in a static library?
takeshimiya:
Change
--- Code: (cpp) ---#include "string.h"
--- End code ---
to
--- Code: (cpp) ---#include <string>
--- End code ---
thomas:
That's not the cause of the error. It is incorrect, but it would probably still work with a deprecation warning.
The cause of the error is that you compile C, and using is no C keyword.
Change the .c file to .cpp.
sspecter:
ive change the file to cpp. It work now, But i must include it as cpp.
how do I link a file .a in my project?
thomas:
Add the library's name to the "Link libaries" field in project options.
Either use the base name (without lib and .a), i.e. if your library is called libfoo.a then you would just enter foo, or use an absolute file name.
Navigation
[0] Message Index
[#] Next page
Go to full version