Home > Enterprise >  Linking to lib on Linux without headers
Linking to lib on Linux without headers

Time:12-29

Hello I'm trying to link to a library without headers. I wrote prototype exactly as defined in library, but ld cannot link it.

readelf -Ws Release/libcef.so | grep KeyStringToDomKey

386822: 00000000066d73d0   328 FUNC    LOCAL  HIDDEN    17 _ZN2ui16KeycodeConverter17KeyStringToDomKeyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE

readelf -Ws main-6cf4e2.o | grep KeyStringToDomKey

  13: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _ZN2ui16KeycodeConverter17KeyStringToDomKeyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE
#include <iostream>
#include <string>
#include "domkey.h"

namespace ui {
    class KeycodeConverter {
    public:
        static DomKey KeyStringToDomKey(const std::string&);
    };
}

using namespace std;

int main()
{
    auto t = ui::KeycodeConverter::KeyStringToDomKey("t");
    cout << "Hello World!" << endl;
    return 0;
}

CodePudding user response:

386822: 00000000066d73d0 328 FUNC LOCAL HIDDEN 17 _ZN2u...

HIDDEN is the key here: this symbol is not visible outside of the shared library (neither to static linker /usr/bin/ld, nor to the dynamic loader).

  • Related