Linux default search path

gcc replacing default library search paths

I want to make a «bare bones» Linux environment, so first I compile and install the Linux kernel to a directory called /distro (on the «host» machine). After configuring the boot loader, I am able to boot into this kernel and it naturally pauses immediately as it cannot find /sbin/init to execute. So then I want to run bash in this environment, so I attempt to compile bash and it works. However, the bash package depends on headers and libraries from the ncurses and readline packages. I haven’t installed these packages into /distro, so the reason that the compilation succeeded is because it used the ncurses and readline from the host machine, which I do not want. In other words, I want the bash build process to actually fail because I have not installed ncurses and readline into /distro. I do not want the build process to use any packages in the host machine. For include paths this is easy as I can do this:

./configure CFLAGS="-nostdinc -I/distro/usr/include -I/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/include" 

The -nostdinc option tells GCC to not search in standard paths such as /usr/include and the like, and then I manually specify the include directory in /distro, and also a necessary directory that contains headers essential to GCC even though they are on the host machine. However there doesn’t appear to be a GCC option like -nostdinc for libraries. As far as I know, there are two ways to glean the default library search paths that GCC uses:

gcc -print-search-dirs | grep libraries gcc --verbose a.c 2>&1 | grep LIBRARY_PATH 

which apparently are not the same, but I’m assuming that -print-search-dirs is more complete. As far as binutils ld is concerned, the -T option can be used to use a script file without any SEARCH_DIR entries. So, the only way to replace the GCC default library search paths is to hack the sources and compile a custom GCC? There really should be some sort of option for this.

Читайте также:  Bluetooth mouse linux mint

Источник

Override/clear g++ default search path for libraries

I want to override/clear g++ default search path for libraries, so that g++ does only search libraries under paths explicitly specified:

$ arm-linux-gnueabihf-g++ --print-search-dirs | grep libraries: libraries: =/usr/lib/gcc-cross/arm-linux-gnueabihf/6/:/usr/lib/gcc-cross/arm-lin ux-gnueabihf/6/../../../../arm-linux-gnueabihf/lib/arm-linux-gnueabihf/6/:/usr/l ib/gcc-cross/arm-linux-gnueabihf/6/../../../../arm-linux-gnueabihf/lib/arm-linux -gnueabihf/:/usr/lib/gcc-cross/arm-linux-gnueabihf/6/../../../../arm-linux-gnuea bihf/lib/../lib/:/lib/arm-linux-gnueabihf/6/:/lib/arm-linux-gnueabihf/:/lib/../l ib/:/usr/lib/arm-linux-gnueabihf/6/:/usr/lib/arm-linux-gnueabihf/:/usr/lib/../li b/:/usr/lib/gcc-cross/arm-linux-gnueabihf/6/../../../../arm-linux-gnueabihf/lib/ :/lib/:/usr/lib/ 

Background

I’m on Ubuntu 17.04 compiling c++ code for several cross-platform distributions. I’ve installed Ubuntu g++-arm-linux-gnueabihf package, and created a target image under /opt/jessie_root, in this case for Jessie armhf. I also fixed all the links under this jessie_root image to be relative and not absolute. I want to compile dynamic executables with the target rootfs libraries. Initially I was compiling «fine» but I realized that I was linking to symbols on the host cross-toolchain libstdc++. I’m using cmake, but for simplicity consider this commands:

/usr/bin/arm-linux-gnueabihf-g++ main.c 

This will link to the host libstdc++ under /usr/lib/gcc-cross/arm-linux-gnueabihf/6/libstdc++.so , which is not desirable.

/usr/bin/arm-linux-gnueabihf-g++ main.cpp --sysroot=/opt/jessie_root -L=/usr/lib/gcc/arm-linux-gnueabihf/4.9 -D_GLIBCXX_USE_CXX11_ABI=0 

This will link correctly to the target libstdc++ under /opt/jessie_root/usr/lib/gcc/arm-linux-gnueabihf/4.9/libstdc++.so , which I want. The issue is that this seems a disaster waiting to happen, as if one of the default libs are not found on the target, the compiler will haply take one from the host cross-toolchain. I could remove or rename them, but I don’t want to mess on /usr/. I have also played with GCC -nostdlib and LD -nostdlib , which seem to have different meanings. GCC -nostdlib is for libraries, and LD -nostdlib is for the search directories. LD -nostdlib have no effect, and GCC -nostdlib just forces me to specify the libraries manually, but it still keeps the search paths. Naturally I could use another toolchain/compile my own, but I would prefer to stay on the packaged toolchain.

Читайте также:  Linux команда top закончить

Источник

what is default path for header file included in c program?

Try running gcc -v -E — . When I do, part of the output is as follows:

#include search starts here: /usr/lib/gcc/i686-linux-gnu/4.6.1/include /usr/local/include /usr/lib/gcc/i686-linux-gnu/4.6.1/include-fixed /usr/include/i386-linux-gnu /usr/include 

It’s not an answer to the gstreamer question, but I hope this still helps!

/usr/local/include /usr/include 

If you use another path, you can add in your compile command with -I flag. In your case, assuming you have a /usr/local/gst/include directory, you may add -I/usr/local/gst/include and use #include

The path searched depends on the implementation (and current configuration). The correct way to find the include path is to use pkg-config

pkg-config --cflags gstreamer 

it shows this error —> Package gstreamer was not found in the pkg-config search path. Perhaps you should add the directory containing `gstreamer.pc’ to the PKG_CONFIG_PATH environment variable No package ‘gstreamer’ found

@Mr.32 Perhaps you need to specify a version. Or maybe gstreamer isn’t correctly installed. Look in /usr/lib/pkgconfig and /usr/share/pkgconfig .

@Mr.32: As cnicutar has pointed out you need to use pkg-config. For gstreamer it is not just gstreamer, it is gstreamer-. As you have installed gstreamer in /usr/local check the output of ls /usr/local/lib/pkgconfig/gstreamer* , you should find a bunch of .pc files. Now try this: export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig then pkg-config —cflags gstreamer-0.10 assuming you found gstreamer-0.10.pc in ls command. Does that show any output?

Источник

Оцените статью
Adblock
detector