Posts

Showing posts from April, 2007

Simple Test Unix C++ Source Compilation and Makefile

Create 3 (*.C) files /* main.C */ #include <stdlib.h> #include <stdio.h> #include "1.h" extern void test2(); extern void test3(); void test1() { } int main() { test1(); test2(); test3(); exit (EXIT_SUCCESS); } /* 2.C */ #include "1.h" #include "2.h" void test2() { } /* 3.C */ #include "2.h" #include "3.h" void test3() { } Create 3 (*.h) files touch 1.h touch 2.h touch 3.h Then, Create a makefile with content (note: <tab> should be a real tab. Tab is very important or else you will else funny compiler message) testing123: main.o 2.o 3.o <tab>g++ -o myapp main.o 2.o 3.o main.o: main.C 1.h <tab>g++ -c main.C 2.o: 2.C 1.h 2.h <tab>g++ -c 2.C 3.o: 3.C 2.h 3.h <tab>g++ -c 3.C Then run make -f makefile then export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/apps/public/lib (for C++ libraries since g++ is to compile CPP files) Then, just run "testing123" (note: In Unix, *. a is a static library where