2

I've installed libssh following the instructions and even though everything seems to be OK my compiler still returns the error "file not found" in the line "#include ". I guess it has something to do with directories or links (I have "make install" in the same folder where I downloaded it) but I don't know where should I put it so I can #include it in any project.

This is how I installed it: I downloaded it and unzip it into the folder "libssh" on my Desktop (Mac).

Then I did

cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
make

and finally:

sudo make install

Then in my program I have:

#include <libssh/sftp.h>

And XCode returns: "libssh/sftp.h file not found". I tried adding the libssh folder in the Desktop to the project, but I still have similar problems.

I guess I should install it (somehow) to the /usr/include folder, so that any project can use it (like pthread or many others), but I don't know how to do this.

If I include any other file in /usr/include it works fine (like ) but when I #include it returns file not found, even though if I cd to /usr/include/libssh the file libssh.h does exist.

This is the very simple sample code:

#include <stdio.h>
#include <pthread.h> //OK
#include <libssh/libssh.h> //Not OK, file not found.

int main(int argc, const char * argv[])
{
    printf("Hello World!");
    return 0;
}
ckruczek
  • 2,361
  • 2
  • 20
  • 23
P. Lacosta
  • 49
  • 1
  • 1
  • 4
  • @ckruczek I downloaded it and unzip it into the folder "libssh" on my Desktop. Then I did (|| means new line): "cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug .." || "make" and finally: "sudo make install" – P. Lacosta Aug 19 '15 at 11:44
  • So please provide the code you tried to compile and the error messages the compiler has thrown.... Please provide as much information as needed to help you. – ckruczek Aug 19 '15 at 11:48
  • 1
    Ok and how do you compile your test programm. Man you have to give us all the information that are needed to help you. Asking you for each and every little thing is kind of annoying. – ckruczek Aug 19 '15 at 12:06
  • @ckruczek I'm sorry, I don't know what you mean. I just press "play". If I include any other file in /usr/include it works fine (like ) but when I #include it returns file not found, even though if I cd to /usr/include/libssh the file libssh.h does exist. – P. Lacosta Aug 19 '15 at 12:18
  • Yes...you just press 'play'.... Thats bothering me even more...So without any hint of you about how you compile I can't help you. Did you included the lib in your linking process? `gcc -lssh test.c -o test.o` or something like this? – ckruczek Aug 19 '15 at 12:20
  • @ckruczek Truth is I don't know a lot about linking. I read this but it doesn't have much information: http://api.libssh.org/master/libssh_linking.html I also tried "brew install libssh" and even though it was installed properly it doesn't work neither. I thought that if you have the library in /usr/include the compiler will automatically link it. For instance, the pthread.h file is included properly without doing anything. If you tell me which information you want about the compiling process and how to get it I would gladly post it here. – P. Lacosta Aug 19 '15 at 12:37

2 Answers2

2

In the tutorial is described how you have to link the library

You have two possibilities here:

  1. As described you have to add those two lines to your code

    #define LIBSSH_STATIC 1

    #include <libssh/libssh.h>

  2. You compile your code with the LIBSSH_STATIC flag.

    gcc -DLIBSSH_STATIC test.c -o test.o

I thought that if you have the library in /usr/include the compiler will automatically link it. For instance, the pthread.h file is included properly without doing anything.

This is a system library which gets linked automatically most of the time. libssh is not. Thats why you have to be more specific on how to compile/link it.

ckruczek
  • 2,361
  • 2
  • 20
  • 23
0

Ive had a very similar problem several times and I have solved it by removing the ≤ ≥ symbols from around my header files and using ""s and the absolute path to the header file you're including. Now this doesn't solve your libssh install problems but it will allow you to compile just the way you have it as long as you know the absolute path of your header file and all of your header's dependencies are in the respective locations that they were inteded to look for them in. Hope this helps.