- test5-execsymbols checks that a module can reach symbols that are defined in

the executable.  On linux you can.
This commit is contained in:
Bryce Denney 2002-10-11 16:45:31 +00:00
parent 043167e8cc
commit 5b535b7e83
8 changed files with 135 additions and 0 deletions

View File

@ -0,0 +1,32 @@
CXX=g++
CXXFLAGS=-Wall -g
LIBTOOL=libtool
RPATH=`pwd`/lib
all: uselib
uselib: uselib.cc libmodule1.la libmodule2.la
$(LIBTOOL) $(CXX) $(CXXFLAGS) -o uselib uselib.cc libmodule1.la libmodule2.la
libmodule1.la: module1.lo libmodule2.la
$(LIBTOOL) $(CXX) -no-undefined -o libmodule1.la module1.lo -rpath ${RPATH} libmodule2.la
mkdir -p lib bin
$(LIBTOOL) cp libmodule1.la ${RPATH}
libmodule2.la: module2.lo
$(LIBTOOL) $(CXX) -no-undefined -o libmodule2.la module2.lo -rpath ${RPATH}
mkdir -p lib bin
$(LIBTOOL) cp libmodule2.la ${RPATH}
%.lo: %.cc
$(LIBTOOL) $(CXX) -c $<
test:
@echo "*** Running test in `pwd`"
-./uselib
@echo "*** Test done in `pwd`"
clean:
-libtool rm libmodule1.la module1.lo libmodule2.la module2.lo
rm -rf *.o uselib.exe bin lib uselib uselib.exe
rm -rf .libs

View File

@ -0,0 +1,12 @@
test5-execsymbols
Can a module reference symbols in the executable?
module1 exports module_name and operate(int,int).
module2 exports n_operations and operation_occurred().
uselib.cc uses symbols and functions from both modules.
Module1 calls operation_occurred() in module2.
Module2 calls register_module() in uselib.cc the first time
it is called.

View File

@ -0,0 +1,11 @@
#define MODULE1_DLL_EXPORT
#include "module1.h"
#include "module2.h"
const char *module_name = "AddModule";
int operate (int a, int b)
{
operation_occurred ();
return a + b;
}

View File

@ -0,0 +1,19 @@
#if defined(WIN32) || defined(__CYGWIN__)
# ifdef MODULE1_DLL_EXPORT
# ifdef DLL_EXPORT
# warning I will export DLL symbols for MODULE1
# define MODULE1API(type) __declspec(dllexport) type
# endif
# else
# warning I will import DLL symbols for MODULE1
# define MODULE1API(type) __declspec(dllimport) type
# endif
#endif
#ifndef MODULE1API
# warning No DLL import/export is needed
# define MODULE1API(type) type
#endif
MODULE1API(extern const char *) module_name;
MODULE1API(extern int) operate (int a, int b);

View File

@ -0,0 +1,16 @@
#include <stdio.h>
#define MODULE2_DLL_EXPORT
#include "module2.h"
#include "uselib.h"
int n_operations = 0;
void operation_occurred () {
static int first_time = 1;
if (first_time) {
register_module ("module2");
first_time = 0;
}
printf ("module2: operation_occurred\n");
n_operations++;
}

View File

@ -0,0 +1,19 @@
#if defined(WIN32) || defined(__CYGWIN__)
# ifdef MODULE2_DLL_EXPORT
# ifdef DLL_EXPORT
# warning I will export DLL symbols for MODULE2
# define MODULE2API(type) __declspec(dllexport) type
# endif
# else
# warning I will import DLL symbols for MODULE2
# define MODULE2API(type) __declspec(dllimport) type
# endif
#endif
#ifndef MODULE2API
# warning No DLL import/export is needed
# define MODULE2API(type) type
#endif
MODULE2API(extern int) n_operations;
MODULE2API(void) operation_occurred ();

View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include "module1.h"
#include "module2.h"
#include "uselib.h"
int register_module (const char *name)
{
printf ("register_module was called by module '%s'\n", name);
return 0;
}
int main ()
{
printf ("start\n");
printf ("at first, n_operations = %d\n", n_operations);
printf ("Module name is '%s'\n", module_name);
int a=5, b=12;
int c = operate (a, b);
printf ("operate(%d,%d) = %d\n", a, b, c);
int d = operate (a, c);
printf ("operate(%d,%d) = %d\n", a, c, d);
printf ("stop\n");
printf ("at end, n_operations = %d\n", n_operations);
return 0;
}

View File

@ -0,0 +1 @@
extern int register_module (const char *name);