Statically link libclang

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Statically link libclang

Xin Wang via cfe-dev
I'm trying to statically link libclang in one of my tools [1]. The
problem I have is to get the correct order of the LLVM and libclang
libraries when linking. On macOS it seems I can pass the libraries to
the linker in any order but that doesn't work on Linux.

I've looked at llvm-config, but that doesn't contain any information
about libclang, only LLVM. I've tried specifying the order of the
libraries exactly as specified in
"tools/clang/tools/libclang/CMakeFiles/libclang.dir/link.txt" after
invoking cmake and that works.

Is there a way to get/extract the correct order of the libraries
programmatically without having to hard code the order? Ideally
something that works across different versions of libclang.

[1] https://github.com/jacob-carlborg/dstep

--
/Jacob Carlborg

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Statically link libclang

Xin Wang via cfe-dev
On 2017-06-26 21:51, Jacob Carlborg via cfe-dev wrote:

> I'm trying to statically link libclang in one of my tools [1]. The
> problem I have is to get the correct order of the LLVM and libclang
> libraries when linking. On macOS it seems I can pass the libraries to
> the linker in any order but that doesn't work on Linux.
>
> I've looked at llvm-config, but that doesn't contain any information
> about libclang, only LLVM. I've tried specifying the order of the
> libraries exactly as specified in
> "tools/clang/tools/libclang/CMakeFiles/libclang.dir/link.txt" after
> invoking cmake and that works.
>
> Is there a way to get/extract the correct order of the libraries
> programmatically without having to hard code the order? Ideally
> something that works across different versions of libclang.

I came up with a workaround. Extract all LLVM and Clang libraries by
iterating the LLVM lib directory. Pass all libraries prefixed with
libLLVM and libclang to the linker. Use --start-group and --end-group to
help resolve undefined symbols. These flags will instruct the linker to
repeatedly search the libraries until no undefined symbols remain. This
is slower but works.

--
/Jacob Carlborg

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...