Warning: mysql_connect(): No route to host in /home/project-web/cpearls/htdocs/common.php on line 50

Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /home/project-web/cpearls/htdocs/common.php on line 51

Warning: mysql_query() expects parameter 2 to be resource, boolean given in /home/project-web/cpearls/htdocs/common.php on line 54
new Widget
C/C++ Programming Pearls

Simple Compile
Prog1.c needs the test function in  test.c
To compile, so that both programs work together, do the following:
     gcc -o prog test.c prog1.c

However, if you want to create your own library, then, run the following:
     gcc -c test.c
     ar r libpersonal.a test.o
     ranlib libpersonal.a 

or, the ar and ranlib command can be combined as follows:
    ar rs libpersonal.a test.o

next, create the header file, libpersonal.h
    /* libpersonal.h: routines in libpersonal.a */
    extern int test(char *);

To compile the program with the static library:
   gcc -I .  -L .  -o prog1 prog1.c -lpersonal

The -I . tells the gcc to look in the current directory for the new include file. and
-L ., tells gcc to look for the libpersonal.a, library in the current directory as well.
If this example didn't work, make sure you added #include <libpersonal.h> to prog1.c

#include <stdio.h>
int test(char *t)

   program: prog1.c
   dependences: test.c

   compiling this program:
   gcc -o prog test.c prog1.c
#include <stdio.h>
main(int argc, char **argv)
  test("this depend on test.c ");

Creating Your Own configure/Makefile
The following tools can help you create a configuration and Makefile:
  • autoscan
  • autoconf
  • aclocal
  • automake -a
Assume the following directory structure below:
                      \--- stl
                      |       \--- stringSTL.cc
                      \--- prog1
                               \--- prog1.c, test.c
Two programs, stringSTL (a C++ program), and prog1.c ( a C program that depends on test.c). Note, that this is really two separate programs under one project. So currently this is all that exist in the directory tree structure.
The first step is to run autoscan from the project1 directory
$cd project1
$cp configure.scan configure.in
This will produce configure.scan, which in the last command above gets copied to configure.in. Now, what's in configure.in will vary depending upon which version is used. Regardless, configure.in will have to be edited. Below, is what is should look like:
dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/prog1/prog1.c src/stl/stringSTL.cc)

dnl Checks for libraries.

dnl Checks for header files.
dnl Checks for typedefs, structures, and compiler characteristics.

dnl Checks for library functions.

AC_OUTPUT(Makefile src/Makefile src/prog1/Makefile src/stl/Makefile)

Next, you will need to create serveral Makefile.am files, in each of the directories.
SUBDIRS = prog1 stl

bin_PROGRAMS = prog1
prog1_SOURCES = prog1.c test.c

bin_PROGRAMS = stringSTL
stringSTL_SOURCES = stringSTL.cc

Next, run the following:
$automake -a
automake -a may alert you to missing files COPYING, INSTALL, NEWS, README, AUTHORS, and ChangeLog. If so, these files can be created as follows:
It's best to run this command after running automake -a because some versions of automate will create an INSTALL file, plus a few some of the other files. touch will not overwrite any of these; although, you may get a permissions error, which can be ignored.
Next, run automake -a again
$automake -a
If you find errors in configure.in it may be necessary to delete configure, and all config.* files. Do not delete configure.in. Then, run autoconf, aclocal, automake -a again.
SourceForge.net Logo