Allen
Allen

Reputation: 471

How to use C libraries from different path with GCC

I am using Android NDK GCC toolchain to compile a project as command-line. My gcc location is

/opt/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc

And I am using the gcc option

--sysroot=/opt/android-ndk/platforms/android-8/arch-arm/

There is no problem when building Hello World. But for this project, during linking, it produces the error:

/opt/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld:
crtbegin_static.o: No such file: No such file or directory

Actually, the "crtbegin_static.o" is located in

/opt/android-ndk/platforms/android-8/arch-arm/usr/lib

If I put it to

/opt/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3

then this problem can be solved.

Is there anyway to make gcc to locate the crtbegin_static.o correctly.

Upvotes: 1

Views: 2899

Answers (2)

Allen
Allen

Reputation: 471

Finally, I have found the solution. It can be solved by passing the "--sysroot=" option again to the linker, not compiler only, using

-Wl,--sysroot=/opt/android-ndk/platforms/android-8/arch-arm/

Upvotes: 2

kristianp
kristianp

Reputation: 5905

There is a -L option which specifies the directories searched for -l.

http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

http://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html

Upvotes: 1

Related Questions