ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
due to a problem with the ssh server i want to make a modification in the sshlib, therfore i have to (re)build the sshlib myself
i decided to make a trivial test-modification on the sshlib before doing any real changes so i can test if the compile/link/build-process works, but i cant even manage to build sclient with trivial changes in sshlib
i made the follwoing trivial changes to the sshlib:
Code:
added to channels.c
int returnTwoTimes(int in) {
return in*2;
}
Code:
added to libssh.h
int returnTwoTimes(int in);
i was able to build the sshlib without any errors (./configure .... make .... make install )
so my modified sshlib is installed in /usr/local/{include|lib} while the systems original is installed in /usr/{include|lib}
Code:
ls /usr/local/lib
libssh.a libssh.la libssh.so libssh.so.2 libssh.so.2.0.0 python2.5
Code:
ls /usr/local/include/libssh
config.h crypto.h libssh.h server.h sftp.h ssh1.h ssh2.h
Code:
grep 'returnTwo' /usr/local/include/libssh/libssh.h
int returnTwoTimes(int in);
my problem is: i cannot build my sclient using the modified sshlib
Code:
snapshot from sclient.c
#include <stdio.h>
#include <stdlib.h>
#include <libssh/libssh.h>
...
int main() {
int testVar=returnTwoTimes(3);
if (testVar==6) {
return 0;
} else {
return 1;
}
...
when compiling with -lssh he uses the non modified sshlib in /usr/lib/ and not the sshlib in /usr/local/...
Code:
gcc -I/usr/local/include/ -L/usr/local/lib/ -lssh sclient.c
/tmp/ccPqh3b5.o: In function `main':
sclient.c:(.text+0x30): undefined reference to `returnTwoTimes'
collect2: ld returned 1 exit status
when compiling without -lssh he wont find the libssh at all
Code:
gcc -I/usr/local/include/ -L/usr/local/lib/ sclient.c
/tmp/ccwQYFJf.o: In function `main':
sclient.c:(.text+0x30): undefined reference to `returnTwoTimes'
/tmp/ccwQYFJf.o: In function `connect_to_server':
sclient.c:(.text+0x83): undefined reference to `ssh_new'
sclient.c:(.text+0x98): undefined reference to `ssh_set_options'
sclient.c:(.text+0xa3): undefined reference to `ssh_connect'
sclient.c:(.text+0xb7): undefined reference to `ssh_get_error'
/tmp/ccwQYFJf.o: In function `authenticate':
sclient.c:(.text+0xf3): undefined reference to `ssh_userauth_password'
/tmp/ccwQYFJf.o: In function `managechannel':
sclient.c:(.text+0x660): undefined reference to `channel_new'
sclient.c:(.text+0x66e): undefined reference to `channel_open_session'
sclient.c:(.text+0x67d): undefined reference to `ssh_get_error'
sclient.c:(.text+0x698): undefined reference to `channel_request_pty'
sclient.c:(.text+0x6c0): undefined reference to `channel_request_shell'
sclient.c:(.text+0x6cf): undefined reference to `ssh_get_error'
sclient.c:(.text+0x727): undefined reference to `channel_poll'
sclient.c:(.text+0x73b): undefined reference to `ssh_get_error'
sclient.c:(.text+0x766): undefined reference to `channel_write'
sclient.c:(.text+0x78e): undefined reference to `ssh_get_error'
sclient.c:(.text+0x7bb): undefined reference to `channel_is_open'
/tmp/ccwQYFJf.o: In function `set_options':
slient.c:(.text+0x7d5): undefined reference to `ssh_options_new'
slient.c:(.text+0x7ef): undefined reference to `ssh_options_set_username'
sclient.c:(.text+0x806): undefined reference to `ssh_options_set_host'
sclient.c:(.text+0x821): undefined reference to `ssh_options_set_timeout'
/tmp/ccwQYFJf.o: In function `serverknown':
sclient.c:(.text+0x848): undefined reference to `ssh_is_server_known'
sclient.c:(.text+0x8a0): undefined reference to `ssh_get_pubkey_hash'
sclient.c:(.text+0x8ab): undefined reference to `ssh_write_knownhost'
collect2: ld returned 1 exit status
i tryed several -L and -I paramteres already (adding an directory level , leaving out an directory level , giving complete path to files instead of just path to directory) , but nothing worked ...
how do i make gcc build sclient using the sslib in /usr/local/... ??
thanks for help, skaarj
some more system info:
Code:
uname -a
Linux boxName 2.6.27-11-server #1 SMP Wed Apr 1 21:53:55 UTC 2009 i686 GNU/Linux
lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 8.10
Release: 8.10
Codename: intrepid
gcc --version
gcc (Ubuntu 4.3.2-1ubuntu12) 4.3.2
how do i make gcc build sclient using the sslib in /usr/local/... ??
Well, you can try using a symlink - I've often solved these types of library related errors that way.
I. e. in /usr/lib, rename sshlib.a (or whatever) to sshlib.a.old. Then, symlink sshlib.a in /usr/lib to mysshlib.a (or whatever) in /usr/local/lib. Then, if the linker is looking for sshlib.a, it will still find it in /usr/lib, but it will be symlinked to mysshlib.a in /usr/local/lib...
gcc -I/usr/local/include/ -L/usr/local/lib/ sclient.c -lssh
/tmp/ccUqSRGj.o: In function `main':
sclient.c:(.text+0x30): undefined reference to `returnTwoTimes'
collect2: ld returned 1 exit status
Code:
gcc -I/usr/local/include/ sclient.c -o sclient.o
/tmp/ccCwToy8.o: In function `main':
sclient.c:(.text+0x30): undefined reference to `returnTwoTimes'
/tmp/ccCwToy8.o: In function `connect_to_server':
sclient.c:(.text+0x83): undefined reference to `ssh_new'
sclient.c:(.text+0x98): undefined reference to `ssh_set_options'
sclient.c:(.text+0xa3): undefined reference to `ssh_connect'
sclient.c:(.text+0xb7): undefined reference to `ssh_get_error'
/tmp/ccCwToy8.o: In function `authenticate':
sclient.c:(.text+0xf3): undefined reference to `ssh_userauth_password'
/tmp/ccCwToy8.o: In function `managechannel':
sclient.c:(.text+0x660): undefined reference to `channel_new'
sclient.c:(.text+0x66e): undefined reference to `channel_open_session'
sclient.c:(.text+0x67d): undefined reference to `ssh_get_error'
sclient.c:(.text+0x698): undefined reference to `channel_request_pty'
sclient.c:(.text+0x6c0): undefined reference to `channel_request_shell'
sclient.c:(.text+0x6cf): undefined reference to `ssh_get_error'
sclient.c:(.text+0x727): undefined reference to `channel_poll'
sclient.c:(.text+0x73b): undefined reference to `ssh_get_error'
sclient.c:(.text+0x766): undefined reference to `channel_write'
sclient.c:(.text+0x78e): undefined reference to `ssh_get_error'
sclient.c:(.text+0x7bb): undefined reference to `channel_is_open'
/tmp/ccCwToy8.o: In function `set_options':
sclient.c:(.text+0x7d5): undefined reference to `ssh_options_new'
sclient.c:(.text+0x7ef): undefined reference to `ssh_options_set_username'
sclient.c:(.text+0x806): undefined reference to `ssh_options_set_host'
sclient.c:(.text+0x821): undefined reference to `ssh_options_set_timeout'
/tmp/ccCwToy8.o: In function `serverknown':
sclient.c:(.text+0x848): undefined reference to `ssh_is_server_known'
sclient.c:(.text+0x8a0): undefined reference to `ssh_get_pubkey_hash'
sclient.c:(.text+0x8ab): undefined reference to `ssh_write_knownhost'
collect2: ld returned 1 exit status
gcc -I/usr/local/include/ -L/usr/local/lib/ sclient.c -lssh
/tmp/ccUqSRGj.o: In function `main':
sclient.c:(.text+0x30): undefined reference to `returnTwoTimes'
collect2: ld returned 1 exit status
Code:
gcc -I/usr/local/include/ sclient.c -o sclient.o
/tmp/ccCwToy8.o: In function `main':
sclient.c:(.text+0x30): undefined reference to `returnTwoTimes'
/tmp/ccCwToy8.o: In function `connect_to_server':
sclient.c:(.text+0x83): undefined reference to `ssh_new'
sclient.c:(.text+0x98): undefined reference to `ssh_set_options'
sclient.c:(.text+0xa3): undefined reference to `ssh_connect'
sclient.c:(.text+0xb7): undefined reference to `ssh_get_error'
/tmp/ccCwToy8.o: In function `authenticate':
sclient.c:(.text+0xf3): undefined reference to `ssh_userauth_password'
/tmp/ccCwToy8.o: In function `managechannel':
sclient.c:(.text+0x660): undefined reference to `channel_new'
sclient.c:(.text+0x66e): undefined reference to `channel_open_session'
sclient.c:(.text+0x67d): undefined reference to `ssh_get_error'
sclient.c:(.text+0x698): undefined reference to `channel_request_pty'
sclient.c:(.text+0x6c0): undefined reference to `channel_request_shell'
sclient.c:(.text+0x6cf): undefined reference to `ssh_get_error'
sclient.c:(.text+0x727): undefined reference to `channel_poll'
sclient.c:(.text+0x73b): undefined reference to `ssh_get_error'
sclient.c:(.text+0x766): undefined reference to `channel_write'
sclient.c:(.text+0x78e): undefined reference to `ssh_get_error'
sclient.c:(.text+0x7bb): undefined reference to `channel_is_open'
/tmp/ccCwToy8.o: In function `set_options':
sclient.c:(.text+0x7d5): undefined reference to `ssh_options_new'
sclient.c:(.text+0x7ef): undefined reference to `ssh_options_set_username'
sclient.c:(.text+0x806): undefined reference to `ssh_options_set_host'
sclient.c:(.text+0x821): undefined reference to `ssh_options_set_timeout'
/tmp/ccCwToy8.o: In function `serverknown':
sclient.c:(.text+0x848): undefined reference to `ssh_is_server_known'
sclient.c:(.text+0x8a0): undefined reference to `ssh_get_pubkey_hash'
sclient.c:(.text+0x8ab): undefined reference to `ssh_write_knownhost'
collect2: ld returned 1 exit status
Sorry, the second set of commands should have been
gcc -I/usr/local/include/ -c studclient.c -o sclient.o
no output and return code is 0 => works
Code:
gcc -L/usr/local/lib/ sclient.o -lssh
sclient.o: In function `main':
sclient.c:(.text+0x30): undefined reference to `returnTwoTimes'
collect2: ld returned 1 exit status
i also tryed with and without -lssh and i tryed varying the -L parameter ... nothing works
I tried something similar to what you are doing, although the opposite, and it worked for me.
I typically install my library in /usr/local/lib, but for test purposes I installed it in /usr/lib. Then I modified my library code, then built it and installed it /usr/local/lib.
When I built a test app that uses the library, it picked up the one in /usr/local/lib; not the one in /usr/lib.
I think the reason for this is with how 'ldconfig' collects a listing of the libraries that it is made aware of. I have a file in /etc/ld.so.conf.d, name libc.conf that specifies the /usr/local/lib directory.
So if you do not have a libc.conf file, create it with the following contents:
Code:
# libc default configuration
/usr/local/lib
Then, if not already there, place your modified library in /usr/local/lib. Then run the following command as root:
Code:
ldconfig
You should then be able to build your application, and without the need to specify the -L option. Let's hope this works!
Now, I'm off to clean up my /usr/lib folder...
Last edited by dwhitney67; 05-05-2009 at 05:04 PM.
I do not know what to say. Just now, I developed a silly shared-object library, and installed it in /usr/lib.
Then I added a new function to the library, and installed the modified library in /usr/local/lib.
When I built my test application, I specified the library located in /usr/local/lib, so that I could link without any getting any "unresolved reference" errors.
When I ran the application, it automatically loaded the shared-object library in /usr/lib, thus causing the application to abort because it could not reference a symbol (i.e. the function I added).
When I re-ran the application by first specifying the LD_LIBRARY_PATH=/usr/local/lib, then it worked.
Here's my silly library that I tested with...
MyLib.h
Code:
#ifndef MY_LIB_H
#define MY_LIB_H
int doubleTheValue(const int value);
#ifdef MOD
int tripleTheValue(const int value);
#endif
#endif
MyLib.c
Code:
#include "MyLib.h"
int doubleTheValue(const int value)
{
return 2 * value;
}
#ifdef MOD
int tripleTheValue(const int value)
{
return 3 * value;
}
#endif
Anyhow, it seems like you were doing things correctly from the beginning, but merely neglecting to specify the LD_LIBRARY_PATH. Hopefully this will sort out your issues.
Last edited by dwhitney67; 05-05-2009 at 07:57 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.