0

I've been trying to install a library (gzstream), which consists of one .C, one .h and an appropriate makefile. To be able to use #include <gzstream.h>, which gzstream.C uses, I've put the gzstream.h file in /usr/local/include and the gzstream.C in /usr/local/lib.

When I try to compile aufgabe2.cpp, I get the following error message on the terminal. aufgabe2.cpp:1:22: fatal error: /usr/local/include/gzstream.h: Permission denied compilation terminated.

What am I doing wrong?

vivekian2
  • 3,795
  • 9
  • 35
  • 41
Slyforce
  • 5
  • 4
  • 1
    You don't *have* to put it there. You can tell your compiler to look for `#inlcude` files elsewhere. However, what permissions does that file have now? Because I believe `/usr/local/include/` should have read access across the board unless you moved that file as root. If you want to include something without going through that directory, use `g++ -I` Consider: [Tell g++ where to find includes](http://stackoverflow.com/q/15478005/691711) – zero298 Apr 15 '14 at 16:42
  • I'm not that experienced with linux systems, so I don't know what you mean with "moved that file as root". I placed the .h file in `usr/local/include/` through the command `gksudo nautilus` and then copy pasted the file into said directory. Running the command that you gave me, returns the following error `g++: fatal error: no input files` – Slyforce Apr 15 '14 at 17:17

1 Answers1

2

Before being able to use the static library, you need to compile it. This will require you to cd to the directory where the source code for gzstream is present and then type make.

This will compile the library and create an output file libgzstream.a.

Once this is ready, you can include the header file and compile your code. There is no strict need to copy the gzstream.h into /usr/local/include. It may as well reside in the local directory where your source code is present. Then it can be easily included with

#include "gzstream.h" 

See how double quotes are used instead of the angular brackets to indicate relative path in current directory.

The g++ command line should be something like this.

g++ aufgabe2.cpp -L. -lgzstream -lz

-L. tells the linker to look for the static library in the current directory. This assumes that libgzstream.a is copied to your source directory where aufgabe2.cpp is present. If not, then give the relative path to the -L argument where libgzstream.a is present.

Arguments -lgzstream and -lz ask the linker to link these libraries.

vivekian2
  • 3,795
  • 9
  • 35
  • 41
  • I'm dumb, I didn't even think that he hadn't compiled yet, or didn't already have a lib. This is probably the solution. The fact that he put **`gzstream.C`** in the libs should have given it away. – zero298 Apr 15 '14 at 17:09
  • I want to use the angular brackets, because the .C file in the gzstream library uses `#include ` and I wanted to avoid messing around the library files. I guess I could just replace the angular brackets in the .C file. I'll try doing that. – Slyforce Apr 15 '14 at 17:25