jvm_update
jvm_update

Reputation: 265

Compiling a source file that has dependencies on multiple source code trees

How can I compile a C source file that #include's header files from each of two independent source trees? Each source tree has its own set of makefiles, and the source trees are completely independent of each other.

I'm writing a Wireshark plugin which interprets packets of a particular network protocol. In order to compile the plugin, the compiler needs to resolve symbols against the Wireshark source tree. However, in order for the plugin to actually interpret the network packet contents when Wireshark gives it a byte array, the plugin must also include definitions of data structures and RPC XDR routines from an entirely separate source tree. So the compiler also needs to resolve symbols against both Wireshark and a completely separate source tree containing these files.

Is there an easy way to do this? Any suggestions at all would be very much appreciated.

Upvotes: 1

Views: 201

Answers (2)

ASD
ASD

Reputation: 15

If you are using gcc / g++

Use -I flags to include the required header files for compiling.

eg:

g++ -I<includepath1> -I<includepath2> ... -c somefile.cpp -o somefile.o

Use -L flag to link against the libraries. eg:

g++ -o pluginname.so somefile.o somefile2.o somefile3.o -L <libpath1> -l<libname1> -L <libpath2> -l <libname2> <fullpath to .a file for statically linking>

In windows the approach is similar only nomenclature is different, .dll file instead of .so and .lib files instead of .a files.

Upvotes: 0

Harry Seward
Harry Seward

Reputation: 147

Make sure you don't confuse compile with link. Not saying you are, but just pointing out there are two distinct steps.

To compile against tree1 and tree2, use the -I include directive to gcc. gcc -c -I/some/include/for/tree1 -I/some/include/for/tree2 input.c -o output.o

to link against two trees, create .so or .la files (static or dynamic libraries ) from each tree. Call them tree1.la tree2.la. put them in /path/to/tree1/libs and /path/to/tree2/libs

then link

gcc -o prog -ltree1 -ltree2 -L/path/to/tree1/libs -L/path/to/tree2/libs

If the trees are sufficiently large, they should end up creating static or dynamic libraries of object code. Then you just point to their headers to compile and point to their libs to link.

Upvotes: 2

Related Questions