sahlberg / libsmb2

SMB2/3 userspace client
Other
322 stars 135 forks source link

issues using lbsmb2.a #252

Closed zerobytes999 closed 1 year ago

zerobytes999 commented 1 year ago

Hi,

first of all, great library, i was able to use the library on windows to create my own smb client/server.

however, on linux, i was able to compile the library into a static library through the following commands as suggested in one of the issues:

./bootstrap
./configure --prefix=/usr
make

I found the libsmb2.a in the lib folder, created a test program test.c:

#include "stdio.h"

#include "smb2/smb2.h"
#include "smb2/libsmb2.h"
#include "smb2/libsmb2-raw.h"

int main()
{

    struct smb2_context* smb2;
    smb2 = smb2_init_context();
}

Compile commands: gcc -I include -L lib -l:libsmb2.a -static test.c -o mytest

in the include folder, i have all the header files in include folder of libsmb2

I couldn't find why i cannot get past the undefined function issue:

/usr/bin/ld: /tmp/ccp3AAwR.o: in function `main':
test.c:(.text+0x9): undefined reference to `smb2_init_context'
collect2: error: ld returned 1 exit status

can someone please help?

delins commented 1 year ago

I've never seen a colon being used after the -l or in a path. I assume you're getting an error about :libsmb2.a not being found or something. What happens if you remove the colon?

zerobytes999 commented 1 year ago
gcc -I include -L lib -llibsmb2.a -static test.c -o mytest  

/usr/bin/ld: cannot find -llibsmb2.a: No such file or directory
collect2: error: ld returned 1 exit status

this is what i get, it is strange to me also because all examples i found was without include extension and .a

i got this suggestion from here:

gcc -I include -L lib -llibsmb2 -static test.c -o mytest   

/usr/bin/ld: cannot find -llibsmb2: No such file or directory
/usr/bin/ld: note to link with lib/libsmb2.a use -l:libsmb2.a or rename it to liblibsmb2.a
collect2: error: ld returned 1 exit status
delins commented 1 year ago

You probably have to do -lsmb2 then, see the option's description at https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

zerobytes999 commented 1 year ago

do you think the steps i did were ok?

P.S

I was able to compile it without the colons but i still get the undefined error:

gcc -I include -L lib -lsmb2 -static test.c -o mytest  

/usr/bin/ld: /tmp/ccRXxCUF.o: in function `main':
test.c:(.text+0x9): undefined reference to `smb2_init_context'
collect2: error: ld returned 1 exit status
delins commented 1 year ago

You also have to move the -lsmb2 after test.c. It has to do with how gcc looks for required symbols, see https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc.

zerobytes999 commented 1 year ago

hello,

sorry for the late reply. I think i might have figured it out. I'm eventually using x86_64-w64-mingw32-gcc to compile, do i have to use the windows built library?

zerobytes999 commented 1 year ago

thank you very much. In my case, i have to build the library in windows and solve the linking issues within the project.