开发者

USB GCC Development Environment with Libraries

I'm trying to get something of an environment on a usb stick to develop C++ code in. I plan to use other computers, most of the time linux, to work on this from a comma开发者_StackOverflownd line using g++ and make.

The problem is I need to use some libraries, like Lua and OpenGL, which the computers don't have. I cannot add them to the normal directories, I do not have root on these computers. Most of the solutions I've found involve putting things in /usr/lib/ and the like, but I cannot do that. I've also attempted adding options like '-L/media//lib', which is where they are kept, and it didn't work. When compiling, I get the same errors I got when first switching to an OS with the libraries not installed.

Is there somewhere on the computer outside of /usr/ I can put them, or a way to make gcc 'see' them?


You need more than the libraries to be able to compile code utilizing those libraries. (I'm assuming Linux here, things might be slightly different on e.g. OSX,BSDs,Cygwin,Mingw..)

Libraries

For development you need these 3 things when your code uses a library:

  • The library header files, .h files
  • The library development files, libXXX.so or libXXX.a typically
  • The library runtime files , libXXX.so.Y where Y is a version number. These are not needed if you statically link in the library.

You seem to be missing the header files (?) Add them to your usb stick, say under /media/include

Development

  • Use (e.g.) the compiler flag -I/media/include when compiling source code to refer to a non-standard location of header files.
  • Use the compiler/linker flag -L/media/lib to refer to non-standard location of libraries.

You might be missing the first step.

Running

For dynamically linked libraries, the system will load those only from default locations, typically /lib/ , /usr/lib/

Learn the ldd tool to help debug this step.

You need to tell the system where to load additional libraries when you're running a program, here's 3 alternatives:

  • Systemwide: Edit /etc/ld.so.conf and add /media/libs there. Run ldconfig -a afterwards.
  • Local, to the current shell only. set the LD_LIBRARY_PATH environment variable to refer to /media/lib, run export LD_LIBRARY_PATH=/media/lib
  • Executable: Hardcode the non-standard library path in the executable. You add this to the linking step when creating your executable: -Wl,-rpath,/media/lib

Etc.

There could be other reasons things are not working out, if so, show us the output of ls -l /media/libs , and where you put the library header files, the command line you use to compile/link, and the exact errors you get.

  • Missing the headers and/or development libraries (for dynamic libraries there is usually a symlink from a libXXX.so to a libXXX.so.Y , the linker needs the libXXX.so , it will not look directly at libXXX.so.Y)
  • using libraries not compatible with your current OS/architecture. (libraries compiled on one linux distro is often not compatible with another distro, or even another minor version of the same distro)
  • using an usb stick with a FAT32 filesystem, you'll get in trouble with symlinks..
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜