-1

OS : Ubuntu 16.04 32 bit

I am download "C++ Source Code Version 2.07" for azsmb at http://members.inode.at/anton.zechner/az/ .

I follow the AzSmb/SmbDemoLinux/Readme.htm instruction to make SmbDemoLinux project.

================ SmbDemo for Linux

Introduction The SmpDemo is written for the Linux OS. To run the demo you must do following steps:

1. Change to the ./SmbDemoLinux/ directory.

2. Compile the demo with make.
...

I have the error in below:

ubuntu@ubuntu-AngHL:~/FluDrive/AzSmb_2.07/AzSmb/SmbDemoLinux$ make make -C ../SmbLibrary make[1]: Entering directory '/home/ubuntu/FluDrive/AzSmb_2.07/AzSmb/SmbLibrary' make[1]: Nothing to be done for 'all'. make[1]: Leaving directory '/home/ubuntu/FluDrive/AzSmb_2.07/AzSmb/SmbLibrary' cc -lstdc++ -ldl -lrt -lpthread SmbDemo.o ../SmbLibrary/SmbServer.a -o SmbDemo ../SmbLibrary/SmbServer.a(SystemLinux.o): In function SysThreadStart': /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SystemLinux.cpp:2574: undefined reference topthread_attr_setstacksize' /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SystemLinux.cpp:2575: undefined reference to pthread_create' /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SystemLinux.cpp:2582: undefined reference topthread_detach' ../SmbLibrary/SmbServer.a(SystemLinux.o): In function SysSemaphoreCreateEx': /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SystemLinux.cpp:2183: undefined reference topthread_condattr_setclock' ../SmbLibrary/SmbServer.a(SystemLinux.o): In function SysSleep': /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SystemLinux.cpp:2483: undefined reference topthread_condattr_setclock' ../SmbLibrary/SmbServer.a(SocketUtility.o): In function SysSleep(unsigned int)': /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SocketUtility.cpp:990: undefined reference topthread_condattr_setclock' /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SocketUtility.cpp:1001: undefined reference to `pthread_condattr_setclock' collect2: error: ld returned 1 exit status Makefile:20: recipe for target 'SmbDemo' failed make: *** [SmbDemo] Error 1

Questions: 1. May I know how to fix the error?

Tried: 1. Include #include did not help.

    File : AzSmb/SmbServer/System/SystemLinux.cpp

pthread_attr_init(&iAttr); pthread_attr_setstacksize(&iAttr,dwStackSize); //compile error is here if( pthread_create(&iThreadId,&iAttr,SysThreadBegin,pThread)) { free(pThread); return 0; }

It should pass compilation but now fail.

jww
  • 97,681
  • 90
  • 411
  • 885
  • I'm sure there's duplicates which is why I comment instead of answer: The problem is that the GNU linker wants libraries listed *after* object files on the command line. For example, if object file `A.o` depend on library `B`, then `A.o` must be listed before `-lB` on the command line, i.e. doing `cc A.o -lB` instead of `cc -lB A.o`. The project you're building uses the wrong order, with the libraries listed before the object files that depend on the libraries. – Some programmer dude Sep 25 '19 at 08:55
  • @Someprogrammerdude, can you edit the Makefile to fix it? I need more time to digest it. Thank you. – Ang Hock Leong Sep 25 '19 at 09:47
  • Yes the makefile needs to be edited, or the script or program creating the makefile. But I suggest you report it as a bug to the project maintainers so they fix it upstream. – Some programmer dude Sep 25 '19 at 09:56
  • @Someprogrammerdude, I have fetch back to the project maintainers and they will analyze and take action soon. Thank you. – Ang Hock Leong Sep 26 '19 at 01:25

1 Answers1

1
cc -lstdc++ -ldl -lrt -lpthread SmbDemo.o ../SmbLibrary/SmbServer.a -o SmbDemo

Libraries need to be listed last. You must fix the makefile to use the command line like:

cc -o SmbDemo SmbDemo.o ../SmbLibrary/SmbServer.a -lstdc++ -ldl -lrt -lpthread

Also, you should not be adding the -lstdc++ manually. Instead you should use the C++ compiler (CC, not cc), and the C++ compiler will add it for you.

Also see Why does the order in which libraries are linked sometimes cause errors in GCC?

jww
  • 97,681
  • 90
  • 411
  • 885