【问题标题】:Compiler not finding functions declared in header file [duplicate]编译器找不到头文件中声明的函数[重复]
【发布时间】:2016-02-18 18:30:16
【问题描述】:

我需要一些帮助来理解为什么这不起作用。我有一个 .h 文件,它声明了一个在 .so 文件中定义的函数:

/* navApi.h */
void navApi_init();     /* resides in libNavApi.so */

还有一个 .cpp 文件:

/* test.cpp */
#include <iostream>
#include "navApi.h"

int main(void)
{
    std::cout << "start...\n";
    navApi_Init();
}

我编译使用:

g++ test.cpp -navApi

我收到以下错误:

test.cpp: (.txt+0x1e): undefined reference to `navApi_Init()'
collect2: error: ld returned 1 exit status

--在linux、ubuntu上运行--

【问题讨论】:

    标签: c++ compiler-errors shared-libraries .so


    【解决方案1】:

    这是一个链接器错误,没有找到libnavApi.so

    g++ test.cpp -lnavApi
    

    如果libnavApi.so 位于g++ 知道的路径中,可能会起作用。

    【讨论】:

    • 我将 navApi 放入 /usr/bin/ld: 现在我遇到了 seg 错误.. 所以我想编译会工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多