From mboxrd@z Thu Jan 1 00:00:00 1970 From: pkurpis@keck.hawaii.edu (Peter Kurpis) To: carlanunes@yahoo.com Cc: gcc-help@gcc.gnu.org Subject: Re: gcc compile options Date: Thu, 05 Jul 2001 18:40:00 -0000 Message-id: <200107060139.PAA14916@kalani.keck.hawaii.edu> X-SW-Source: 2001-07/msg00085.html > have to do the following: compile multi-thread C++ > programs, generate an executable file and create a > shared library with a list of exported external > symbols of the shared object files. I need to do that > in three distinct steps since I have to use a make > file previously developed for use on AIX (VisualAge > C++ compiler). > > I'm thiinking of using the folowing commands > ("make-like") to compile and create an executable > file, but I don't know how to create shared libraries > and export the symbols... > > compile: > gcc -x c++ -g -Iincdir -c srcdir/*.c objdir/*.o > -mthreads Use g++ to compile c++ code, not gcc -x c++ . Also, you need to use -o to specify the output file. If you are writing a makefile, I would guess you just need to specify the standard make variables, e.g. CXX = g++ CPPFLAGS = -g -Iincdir and use make's implicit rule for .cc files. > create the executable: > gcc -lsomelib -o execfile objfiles The order of libs and objfiles matters, as the linker only makes one pass through the command line resolving symbols. Ordinarily, libs resolve symbols in your objfiles, so g++ -o execfile objfiles -lsomelib Note again the use of g++. It has knowledge of what to link against implicitly, a different set of things than gcc. To create a shared library, since you are using the GNU ld (inherently configured into gcc): g++ -shared -o sharedlib objfiles I haven't looked up whether you can create a list of exported symbols at link time -- you probably can, and you can pass the option to ld via -Wl,-xxx where xxx is the option string. (See man ld for the right thing.) Alternatively, you can use nm and grep to do the same thing.