Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Generating .so library with C code. (I am facing errors with this workflow)
Generating .so library with C code. [message #1842356] Thu, 17 June 2021 04:08 Go to next message
Zuo  Zhuang is currently offline Zuo ZhuangFriend
Messages: 1
Registered: June 2021
Junior Member
Hi all.
My goal is to integrate some MATLAB function into my NI Linux Hardware.
I have the .C code that is generated from MATLAB, and I encounter many errors while trying to compile the .C code to .so library.
I have created a project > Shared Library> Empty Project> Cross GCC.
I tested with this simple sample code


#include "stdio.h"
#include <stdlib.h>

int main(void) {
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
return EXIT_SUCCESS;
}



I build the project and encounters this error. Does anyone knows how do I resolve this error?

12:07:31 **** Incremental Build of configuration Debug for project shared_lib ****
Info: Internal Builder is used for build
x86_64-nilrt-linux-gcc "-LC:\\build\\17.0\\x64\\sysroots\\core2-64-nilrt-linux\\usr\\include" "-LC:\\build\\17.0\\x64\\sysroots\\core2-64-nilrt-linux\\usr\\include\\c++\\4.9.2\\x86_64-nilrt-linux" "-LC:\\build\\17.0\\x64\\sysroots\\core2-64-nilrt-linux\\usr\\include\\c++\\4.9.2" -shared -o libshared_lib.so test1.o
c:/build/17.0/x64/sysroots/i686-nilrtsdk-mingw32/usr/bin/x86_64-nilrt-linux/../../libexec/x86_64-nilrt-linux/gcc/x86_64-nilrt-linux/4.9.2/ld.exe: cannot find crti.o: No such file or directory
c:/build/17.0/x64/sysroots/i686-nilrtsdk-mingw32/usr/bin/x86_64-nilrt-linux/../../libexec/x86_64-nilrt-linux/gcc/x86_64-nilrt-linux/4.9.2/ld.exe: cannot find crtbeginS.o: No such file or directory
c:/build/17.0/x64/sysroots/i686-nilrtsdk-mingw32/usr/bin/x86_64-nilrt-linux/../../libexec/x86_64-nilrt-linux/gcc/x86_64-nilrt-linux/4.9.2/ld.exe: cannot find -lgcc
c:/build/17.0/x64/sysroots/i686-nilrtsdk-mingw32/usr/bin/x86_64-nilrt-linux/../../libexec/x86_64-nilrt-linux/gcc/x86_64-nilrt-linux/4.9.2/ld.exe: cannot find -lgcc_s
c:/build/17.0/x64/sysroots/i686-nilrtsdk-mingw32/usr/bin/x86_64-nilrt-linux/../../libexec/x86_64-nilrt-linux/gcc/x86_64-nilrt-linux/4.9.2/ld.exe: cannot find -lc
c:/build/17.0/x64/sysroots/i686-nilrtsdk-mingw32/usr/bin/x86_64-nilrt-linux/../../libexec/x86_64-nilrt-linux/gcc/x86_64-nilrt-linux/4.9.2/ld.exe: cannot find -lgcc
c:/build/17.0/x64/sysroots/i686-nilrtsdk-mingw32/usr/bin/x86_64-nilrt-linux/../../libexec/x86_64-nilrt-linux/gcc/x86_64-nilrt-linux/4.9.2/ld.exe: cannot find -lgcc_s
c:/build/17.0/x64/sysroots/i686-nilrtsdk-mingw32/usr/bin/x86_64-nilrt-linux/../../libexec/x86_64-nilrt-linux/gcc/x86_64-nilrt-linux/4.9.2/ld.exe: cannot find crtendS.o: No such file or directory
c:/build/17.0/x64/sysroots/i686-nilrtsdk-mingw32/usr/bin/x86_64-nilrt-linux/../../libexec/x86_64-nilrt-linux/gcc/x86_64-nilrt-linux/4.9.2/ld.exe: cannot find crtn.o: No such file or directory
collect2.exe: error: ld returned 1 exit status

12:07:32 Build Finished (took 799ms)



Re: Generating .so library with C code. [message #1842426 is a reply to message #1842356] Fri, 18 June 2021 14:23 Go to previous message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
The linker is saying it couldn't find libraries libgcc, libgcc_s and libc in the paths you've given.
I'm not sure what extents would be used for them but likely .a or .so
but they may be different under windows.

C:\\build\\17.0\\x64\\sysroots\\core2-64-nilrt-linux\\usr\\include and the others would seem to be
directories containing header files and not libraries.
I would normally expect them in a path containing /usr/lib or similar
but since you are using a variant of gcc they could be elsewhere.

It's also saying it couldn't find modules crtio.o, crtbeginS.o, crtendS.o, and crtn.o
That means they are not in any library searched by the linker.
These are in the core C Run Time (CRT) library (or libraries)
Normally the linker (ld.exe) has the paths to CRT libraries built-in.
You may need to find them and supply the path using the -L and -l (small L) options.
But then these are used as startup/exit code run before and after the C main
which usually isn't in a dynamic library.

https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html

You can see what the default library paths are by adding -print-search-dirs to the link step.

BTW: Dynamic libraries may not be supported in your target environment.
They usually require OS support.
Can you really use them on your target?
If so, you need to pay attention to dynamic library requirements for your intended target.
If not, you may want to consider using/building static libraries.

[Updated on: Fri, 18 June 2021 14:40]

Report message to a moderator

Previous Topic:Program g++ and gcc NOT FOUND In PATH!!!!!
Next Topic:how to import vc++ project in Eclipse IDE
Goto Forum:
  


Current Time: Fri Apr 26 15:10:19 GMT 2024

Powered by FUDForum. Page generated in 0.15598 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top