This question already has answers here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
                                
                                    (9个答案)
                                
                        
                        
                            What is an undefined reference/unresolved external symbol error and how do I fix it?
                                
                                    (32个答案)
                                
                        
                                5个月前关闭。
            
                    
操作系统:Ubuntu 16.04 32 bit

我在http://members.inode.at/anton.zechner/az/处为assmb下载了“ C ++源代码版本2.07”。

我按照AzSmb / SmbDemoLinux / Readme.htm指令进行SmbDemoLinux项目。

================
适用于Linux的SmbDemo

介绍
SmpDemo是为Linux操作系统编写的。要运行演示,您必须执行以下步骤:

1. Change to the ./SmbDemoLinux/ directory.

2. Compile the demo with make.
...


我在下面的错误:


  ubuntu @ ubuntu-AngHL:〜/ FluDrive / AzSmb_2.07 / AzSmb / SmbDemoLinux $ make
  make -C ../SmbLibrary make [1]:进入目录
  '/home/ubuntu/FluDrive/AzSmb_2.07/AzSmb/SmbLibrary'make [1]:无
  为“全部”完成。 make [1]:离开目录
  '/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):在功能中
  SysThreadStart': /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SystemLinux.cpp:2574: undefined reference to pthread_attr_setstacksize'
  /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SystemLinux.cpp:2575:
  对pthread_create' /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SystemLinux.cpp:2582: undefined reference to pthread_detach的未定义引用
  ../SmbLibrary/SmbServer.a(SystemLinux.o):在功能中
  SysSemaphoreCreateEx': /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SystemLinux.cpp:2183: undefined reference to pthread_condattr_setclock'
  ../SmbLibrary/SmbServer.a(SystemLinux.o):在函数SysSleep': /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SystemLinux.cpp:2483: undefined reference to pthread_condattr_setclock'中
  ../SmbLibrary/SmbServer.a(SocketUtility.o)​​:在函数中
  SysSleep(unsigned int)': /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SocketUtility.cpp:990: undefined reference to pthread_condattr_setclock'
  /home/ubuntu/FluDrive/AzSmb/AzSmb/SmbLibrary/../SmbServer/System/SocketUtility.cpp:1001:
  未定义对“ pthread_condattr_setclock” collect2的引用:错误:ld
  返回1个退出状态Makefile:20:目标'SmbDemo'的配方失败
  make:*** [SmbDemo]错误1


问题:
1.我可以知道如何解决该错误吗?

尝试过:
1.包含#include没有帮助。

    File : AzSmb/SmbServer/System/SystemLinux.cpp


pthread_attr_init(&iAttr);
        pthread_attr_setstacksize(&iAttr,dwStackSize); //编译错误在这里
    if(pthread_create(&iThreadId,&iAttr,SysThreadBegin,pThread))
        {
        free(pThread);
        返回0;
        }

它应该可以通过编译,但是现在失败了。

最佳答案

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



库需要最后列出。您必须修复makefile以使用命令行,例如:

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


另外,您不应该手动添加-lstdc++。相反,您应该使用C ++编译器(CC,而不是cc),并且C ++编译器会为您添加它。

另请参见Why does the order in which libraries are linked sometimes cause errors in GCC?

08-05 06:06