Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans: how to include other c++ static library project?

Tags:

c++

netbeans

I am really new to c++ and am using Netbeans for now.

I managed to create a Sign.h and Sign.cpp containing a working class Sign. I added these to a Console Project and it works great:

  #include <iostream>
  #include <ostream>
  #include "Sign.h"

  int main()
  {
      Sign sign = Sign::parse("b");
      std::cout << sign.toString() << " " << sign.getValue() <<"\n";
  }

However, I want to create a static library containing the Sign class, so I created a static library and added Sign.cpp and Sign.h to it. The problem now is, that I can't seem to get my Sign class to be included in the main console program.

I added the library in Options => Build => Linker => Libraries, and added it to the required projects. However I can't use #include <Sign> or #include <Sign.h>.

What am I missing here?

like image 868
Peterdk Avatar asked Jul 16 '10 11:07

Peterdk


People also ask

Can you code c in NetBeans?

NetBeans C/C support lets you create C and C Application and Library projects with generated makefiles, as well as C and C++ projects with existing sources. You can build, run, and debug your project on the local host (the system from which you started the IDE) or on a remote host running a UNIX® operating system.

How are static libraries linked?

Static libraries are created by copying all necessary library modules used in a program into the final executable image. The linker links static libraries as a last step in the compilation process. An executable is created by resolving external references, combining the library routines with program code.

Where do I put my static library?

Static libraries belong next to their corresponding dynamic libraries, and in accordance with the FHS. Keep in mind that static libraries are usually only needed to build software, not run it.


1 Answers

You need two files from a library. The library file (.lib on windows, .a on linux) and the include file (.h files).

The Options => Build => Linker => Libraries is only for the library file. You also need to set the path for the includes under File => Project Properties => Build => C++ Compiler => General => Include Directories

like image 122
Victor Marzo Avatar answered Oct 15 '22 00:10

Victor Marzo