Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Static library linking in C::B  (Read 1910 times)

0 Members and 1 Guest are viewing this topic.

Shimajda

  • Newbie
  • *
  • Posts: 17
    • View Profile
Static library linking in C::B
« on: March 19, 2010, 06:36:47 pm »
Hi
I have my library using sfml, and after I use my library in other project it return following error:

Code: [Select]
C:\*\cppt\consoleApp\libstl.a(CTest.o)||In function `_ZN5CTestC2Ev':|
C:\*\cppt\stl\CTest.cpp|6|undefined reference to `sf::SocketTCP::SocketTCP()'|
C:\*\cppt\stl\CTest.cpp|7|undefined reference to `sf::IPAddress::IPAddress(char const*)'|
C:\*\cppt\stl\CTest.cpp|7|undefined reference to `sf::SocketTCP::Connect(unsigned short, sf::IPAddress const&, float)'|
C:\*\cppt\stl\CTest.cpp|8|undefined reference to `sf::SocketTCP::Close()'|
C:\*\cppt\consoleApp\libstl.a(CTest.o)||In function `_ZN5CTestC1Ev':|
C:\*\cppt\stl\CTest.cpp|6|undefined reference to `sf::SocketTCP::SocketTCP()'|
C:\*\cppt\stl\CTest.cpp|7|undefined reference to `sf::IPAddress::IPAddress(char const*)'|
C:\*\cppt\stl\CTest.cpp|7|undefined reference to `sf::SocketTCP::Connect(unsigned short, sf::IPAddress const&, float)'|
C:\*\cppt\stl\CTest.cpp|8|undefined reference to `sf::SocketTCP::Close()'|
||=== Build finished: 8 errors, 0 warnings ===|


My Code::Blocks project

I have -lsfml-network-s in my static library. Nothing changes when I add it to project where I use my library.
For me it looks like sfmllib is not included in my lib.

Help :?:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Static library linking in C::B
« Reply #1 on: March 19, 2010, 06:47:03 pm »
There's no link step when compiling a static library, which means that your -lsfml-network-s is ignored. Linking is done only when building a binary (a dynamic library or an executable), so you have to link to sfml-network in your final project.

There is a workaround (that is used for SFML static libraries) which involves using the ar command to manually add the external dependencies to a static library (static libraries are just archives of compiled files).
Laurent Gomila - SFML developer

Shimajda

  • Newbie
  • *
  • Posts: 17
    • View Profile
Static library linking in C::B
« Reply #2 on: March 19, 2010, 08:56:09 pm »
Thanks i have used ar to add external dependencies to my static library and it works:
Code: [Select]
ar rcs my_library.a *.o

Tutorial says that libraries  have to be linked in the right order. How it will work if I make one library from sfml-graphics sfml-window and sfml-system?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Static library linking in C::B
« Reply #3 on: March 19, 2010, 08:57:40 pm »
Quote
How it will work if I make one library from sfml-graphics sfml-window and sfml-system?

It should be ok.
Laurent Gomila - SFML developer