I'm trying to find a way to compile a program that I have with a few external libraries. After some searching, I found an example in O'Reilly's C++ Cookbook.
I have it so that I have the following directory structure with the follwoing files in them:
the .a and .so files can be put in /usr/lib32 or 65 or something like that. Then you don't need to use absolute directory paths... or simply just name them -l[library name]
Also, there might be a problem simply because you're using a capitol L. The shell is funny about typecase and also commands can have different meanings or no meanings at all for capitol letters.
What also might be the probelm as well is you shouldn't have to use libjohnpaul.a as being linked... just the .so files(i'm not sure about this though.)
lmao is this a joke too? your filenames are funny...
I just read a bit more where your problem might be
First you have to type
gcc -c filename
That will turn it to an object file
Then you type
gcc -o [name of exe] [object file] -l[link names]
Thanks for the reply. I tried
gcc -c hellobeatles.cpp
and
g++ -c hellobeatles.cpp
first but I get this error:
hellobeatles.cpp:1:33: fatal error: johnpaul/johnpaul.hpp: No such file or directory
compilation terminated.
Lol the filenames are from the example in the O'Reilly C++ Cookbook. This is the contents of the files:
#include "johnpaul/johnpaul.hpp"
#include " georgeringo/ georgeringo.hpp"
int main( )
{
// Prints "John, Paul, George, and Ringo\n"
johnpaul( );
georgeringo( );
}
The files in the johnpaul folder make up a static library (libjohnpaul.a) and the files in the georgeringo folder make up a dynamic library (libgeorgeringo.so). The library files are created and seem to be fine.
I just don't know how to create an exe from hellobeatles.cpp and link up the library files.
the filenames are from the example in the O'Reilly C++ Cookbook.
Don't they provide a makefile?
Or at least explain how to write one?
To fix
hellobeatles.cpp:1:33: fatal error: johnpaul/johnpaul.hpp: No such file or directory
you need to provide the compiler with a -I command line option, to tell it to check another directory for include files.
g++ -c -I.. hellobeatles.cpp
You need .. as the path here as you want the compiler to look in the parent directory for "johnpaul/johnpaul.hpp" and "georgeringo/ georgeringo.hpp" (I'd lose the space from your version)
(This does assume that hellobeatles, johnpaul, and georgeringo are all subdirs of the same dir.)
Andy
P.S. I use g++ for .cpp and gcc for .c (it prob doesn't really matter, but as it's there...)
Thanks so much!! After giving it the -I file path, it worked fine! That was driving me nuts. The book goes into explaining Make files later on but I couldn't get this bit to work first.