User forums > General (but related to Code::Blocks)
static library [SOLVED]
MortenMacFly:
Here is the proof: It works!
--- Code: ----------------- Build: default in ssptools ---------------
mingw32-g++.exe -IE:\Devel\CodeBlocks\include -c ssptools.cpp -o .objs\ssptools.o
ar.exe -r libssptools.a .objs\ssptools.o
ranlib libssptools.a
ar.exe: creating libssptools.a
-------------- Build: default in cb ---------------
mingw32-g++.exe -Ilib -IE:\Devel\CodeBlocks\include -c main.cpp -o .objs\main.o
mingw32-g++.exe -Llib -LE:\Devel\CodeBlocks\lib -o cb.exe .objs\main.o -lssptools
Process terminated with status 0 (0 minutes, 4 seconds)
0 errors, 0 warnings
--- End code ---
I've attached a ZIP file containing the demo project for you. I hope this will help.
With regards, Morten.
Ps.: Please notify if I can remove the ZIP file again to save forum webspace...
Edit: ZIP file removed (issue solved).
sspecter:
--- Quote ---Yes, I tried! My project consistst of the library and the main. I guess you didn't also remove the namespace from the class (library). Remove this too and it'll work. You have to remove 4 (or were it 5?) lines of code.
Morten.
--- End quote ---
--- Quote ---Here is the proof: It works!
--- End quote ---
Wow! youre right!!! Then i removed ALL "namespace" definitions and references, it worked!
Sorry i didnt tested it shortly after your 2nd post. I was testing other things.
This help a lot. Finally were getting somewere :)
Now i just need to know why it cant find the references definitions then I use the namespace. I am making a program that uses lots of libraries, and I really want use namespaces.
Do static libraries accept namespaces?
--- Quote ---Ps.: Please notify if I can remove the ZIP file again to save forum webspace...
--- End quote ---
sure :) i already tested here
--- Quote ---Could you post your project (source files+project file(s)) in a 7z format (www.7zip.org)? I will give it a try this evening.
--- End quote ---
The project is attached, with the namespaces. I simplified it at maximum, so it is much cleaner than the code i posted before. The file is very small, and i dont have the 7z, so i posted in zip. Hope you dont mind.
Just open the staticlib.workspace and build the console application project. The other project is the static library, it is already built.
[attachment deleted by admin]
sspecter:
I finally found the error :)
I actually had to declare namespace in the header and the library, but I was just declaring it in the header, and calling it in the library. Because of that something got messed up. I still didnt understand what happened with the references then i done that.
Thanks guys, you were really helpfull.
I just have 1 last question:
If you saw my library code you noticed I comented the cout use "cout << msg << endl;". Its because C::B dont recognize cout when i use it in the library. How can I use cout in a library? Or theres another way to output to the console? printf dont recognize my type string :P.
sethjackson:
--- Code: (cpp) ---std::cout << "Hello World!";
--- End code ---
Will work. You could also do
--- Code: (cpp) ---using namespace std;
cout << "Hello World!";
--- End code ---
I always use the first example though......
sspecter:
I just forgot to include iostream. :oops:
Anyway this thread is SOLVED 8)
Thanks again.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version