Author Topic: static library [SOLVED]  (Read 10566 times)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9496
Re: static library
« Reply #15 on: February 27, 2006, 07:54:25 pm »
Here is the proof: It works!
Code: [Select]
-------------- 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
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).
« Last Edit: February 28, 2006, 11:58:56 am by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline sspecter

  • Multiple posting newcomer
  • *
  • Posts: 13
  • I feel like I could... TAKE OVER THE WORLD!!!
Re: static library
« Reply #16 on: February 27, 2006, 08:48:44 pm »
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.

Quote
Here is the proof: It works!

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...

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.

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]
« Last Edit: February 27, 2006, 08:58:19 pm by sspecter »

Offline sspecter

  • Multiple posting newcomer
  • *
  • Posts: 13
  • I feel like I could... TAKE OVER THE WORLD!!!
Re: static library
« Reply #17 on: February 27, 2006, 09:11:53 pm »
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

  • Guest
Re: static library
« Reply #18 on: February 27, 2006, 09:42:12 pm »
Code: C++
  1. std::cout << "Hello World!";
  2.  

Will work. You could also do

Code: C++
  1. using namespace std;
  2.  
  3. cout << "Hello World!";
  4.  

I always use the first example though......

Offline sspecter

  • Multiple posting newcomer
  • *
  • Posts: 13
  • I feel like I could... TAKE OVER THE WORLD!!!
Re: static library
« Reply #19 on: February 27, 2006, 10:11:17 pm »
I just forgot to include iostream.  :oops:

Anyway this thread is SOLVED  8)

Thanks again.

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: static library
« Reply #20 on: February 28, 2006, 11:38:11 am »
Do static libraries accept namespaces?

Hello,

I have slightly modified the projects poseted by MortenMacFly to include the namespace tools. Moreover, I have remarked that there were several declarations using namespace std;. Not all are necessary.

To make it work with the namespace tools, you have to wrap not only ssptools.h, but also ssptools.cpp with:

Quote
namespace tools{
...
};

Then you can use using namespace tools; in the main.cpp.

Code: [Select]
#include <iostream>
#include "ssptools.h"

using namespace tools;

int main()
{
    showMessage("Hello world!\n");
    Point3D p(1,2,3);

    return 0;
}

If you forget to wrap the ssptools.cpp, then it will not works, because in the library there are not the "good" methods. Therefore, you were getting undefined errors.

Also the using namespace std; in the main.cpp and ssptools.cpp are not necessary.

Best wishes,
Michael