Fix to linking problem for Linux in examples.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10600 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Maciej Drwal 2008-06-28 00:06:33 +00:00
commit cdd920a6ca
9 changed files with 71 additions and 34 deletions

View file

@ -1098,15 +1098,18 @@ r_clean:
# Build a C dynamically loadable module
# ----------------------------------------------------------------
CLIBPREFIX = lib
c: $(SRCS)
$(SWIG) -c $(SWIGOPT) $(INTERFACE)
$(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES)
$(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)_$(TARGET)$(SO)
$(CC) $(MAIN) $(TARGET)_proxy.c -L. -l$(LIBPREFIX)_$(TARGET)
$(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(CLIBPREFIX)$(TARGET)$(SO)
$(CC) $(MAIN) $(TARGET)_proxy.c -L. -l$(TARGET)
LD_LIBRARY_PATH=`pwd`:LD_LIBRARY_PATH; export LD_LIBRARY_PATH
c_cpp: $(SRCS)
$(SWIG) -c++ -c $(SWIGOPT) $(INTERFACE)
$(CXX) -c $(CCSHARED) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
$(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)_$(TARGET)$(SO)
$(CC) $(MAIN) $(TARGET)_proxy.c -L. -l$(LIBPREFIX)_$(TARGET)
$(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(CLIBPREFIX)$(TARGET)$(SO)
$(CC) $(MAIN) $(TARGET)_proxy.c -L. -l$(TARGET)
LD_LIBRARY_PATH=`pwd`:LD_LIBRARY_PATH; export LD_LIBRARY_PATH

View file

@ -10,5 +10,5 @@ all::
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MAIN='$(MAIN)' c_cpp
clean:
rm *.o
rm -f *.o *.out *.so *.a

6
Examples/c/class/test.sh Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
./a.out

View file

@ -10,5 +10,5 @@ all::
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MAIN='$(MAIN)' c
clean:
rm *.o
rm -f *.o *.so *.out *.a *~

View file

@ -8,8 +8,8 @@ int main(int argc, char **argv) {
printf("Foo is %f\n", Foo);
printf("Foo by ptr is \%f\n", *Foo_ptr);
printf("my_str is: %s\n", my_str);
printf("array_of_strs contains %s and %s\n", get_str(0), get_str(1));
printf("GCD(%d, %d)=%d\n", a, b, gcd(a, b));
printf("array_of_strs contains %s and %s\n", get_str(0), get_str(1));
return 0;
}

6
Examples/c/simple/test.sh Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
./a.out

View file

@ -69,19 +69,15 @@ public:
}
}
void emitSwigExport(File *f) {
Printf(f, "#ifndef SWIGEXPORT\n");
void emitSwigProtectSymbols(File *f) {
Printf(f, "#ifndef SWIGPROTECT\n");
Printf(f, "# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)\n");
Printf(f, "# if defined(STATIC_LINKED)\n");
Printf(f, "# define SWIGEXPORT\n");
Printf(f, "# else\n");
Printf(f, "# define SWIGEXPORT __declspec(dllexport)\n");
Printf(f, "# endif\n");
Printf(f, "# define SWIGPROTECT //\n");
Printf(f, "# else\n");
Printf(f, "# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)\n");
Printf(f, "# define SWIGEXPORT __attribute__ ((visibility(\"default\")))\n");
Printf(f, "# define SWIGPROTECT __attribute__ ((visibility(\"protected\")))\n");
Printf(f, "# else\n");
Printf(f, "# define SWIGEXPORT\n");
Printf(f, "# define SWIGPROTECT //\n");
Printf(f, "# endif\n");
Printf(f, "# endif\n");
Printf(f, "#endif\n\n");
@ -121,6 +117,7 @@ public:
f_wrappers = NewString("");
Swig_banner(f_runtime);
emitSwigProtectSymbols(f_header);
// FIXME
Printf(f_header, "#include <malloc.h>\n\n");
@ -238,7 +235,6 @@ public:
SwigType *return_type = Getattr(n, "type");
String *return_type_str = SwigType_str(return_type, 0);
String *arg_names = NewString("");
String *arg_lnames = NewString("");
ParmList *parms = Getattr(n, "parms");
// create new function wrapper object
@ -261,7 +257,6 @@ public:
SwigType *type = Getattr(p, "type");
Printv(wrapper->def, SwigType_str(type, 0), " ", Getattr(p, "lname"), np ? ", " : "", NIL);
Printv(arg_names, Getattr(p, "name"), np ? ", " : "", NIL);
Printv(arg_lnames, Getattr(p, "lname"), np ? ", " : "", NIL);
p = np;
}
Printv(wrapper->def, ") {", NIL);
@ -300,7 +295,7 @@ public:
}
// emit proxy functions prototypes
Printv(f_shadow_code_init, "extern ", return_type_str, " _wrap_", name, "(", proto, ");\n", NIL);
Printv(f_shadow_code_init, "extern ", return_type_str, " ", wname, "(", proto, ");\n", NIL);
Printv(f_shadow_code_body, return_type_str, " ", name, "(", proto, ") {\n", NIL);
// handle 'prepend' feature
@ -334,8 +329,13 @@ public:
Printv(f_shadow_header, return_type_str, " ", name, "(", proto, ");\n");
}
// add visibility hint for the compiler
String* vis_hint = NewString("");
Printv(vis_hint, "SWIGPROTECT ", return_type_str, " ", name, "(", ParmList_str(parms), ");\n", NIL);
Printv(f_init, vis_hint, NIL);
Delete(vis_hint);
// cleanup
Delete(arg_lnames);
Delete(arg_names);
Delete(wname);
DelWrapper(wrapper);

View file

@ -4,7 +4,7 @@
# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
# Inc.
timestamp='2006-07-02'
timestamp='2007-03-06'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
@ -161,6 +161,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
arm*) machine=arm-unknown ;;
sh3el) machine=shl-unknown ;;
sh3eb) machine=sh-unknown ;;
sh5el) machine=sh5le-unknown ;;
*) machine=${UNAME_MACHINE_ARCH}-unknown ;;
esac
# The Operating System including object format, if it has switched
@ -780,7 +781,7 @@ EOF
i*:CYGWIN*:*)
echo ${UNAME_MACHINE}-pc-cygwin
exit ;;
i*:MINGW*:*)
*:MINGW*:*)
echo ${UNAME_MACHINE}-pc-mingw32
exit ;;
i*:windows32*:*)
@ -790,12 +791,15 @@ EOF
i*:PW*:*)
echo ${UNAME_MACHINE}-pc-pw32
exit ;;
x86:Interix*:[3456]*)
echo i586-pc-interix${UNAME_RELEASE}
exit ;;
EM64T:Interix*:[3456]*)
echo x86_64-unknown-interix${UNAME_RELEASE}
exit ;;
*:Interix*:[3456]*)
case ${UNAME_MACHINE} in
x86)
echo i586-pc-interix${UNAME_RELEASE}
exit ;;
EM64T | authenticamd)
echo x86_64-unknown-interix${UNAME_RELEASE}
exit ;;
esac ;;
[345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
echo i${UNAME_MACHINE}-pc-mks
exit ;;
@ -950,6 +954,9 @@ EOF
x86_64:Linux:*:*)
echo x86_64-unknown-linux-gnu
exit ;;
xtensa:Linux:*:*)
echo xtensa-unknown-linux-gnu
exit ;;
i*86:Linux:*:*)
# The BFD linker knows what the default object file format is, so
# first see if it will tell us. cd to the root directory to prevent
@ -1208,6 +1215,15 @@ EOF
SX-6:SUPER-UX:*:*)
echo sx6-nec-superux${UNAME_RELEASE}
exit ;;
SX-7:SUPER-UX:*:*)
echo sx7-nec-superux${UNAME_RELEASE}
exit ;;
SX-8:SUPER-UX:*:*)
echo sx8-nec-superux${UNAME_RELEASE}
exit ;;
SX-8R:SUPER-UX:*:*)
echo sx8r-nec-superux${UNAME_RELEASE}
exit ;;
Power*:Rhapsody:*:*)
echo powerpc-apple-rhapsody${UNAME_RELEASE}
exit ;;

View file

@ -4,7 +4,7 @@
# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
# Inc.
timestamp='2006-09-20'
timestamp='2007-01-18'
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
@ -245,12 +245,12 @@ case $basic_machine in
| bfin \
| c4x | clipper \
| d10v | d30v | dlx | dsp16xx \
| fr30 | frv \
| fido | fr30 | frv \
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
| i370 | i860 | i960 | ia64 \
| ip2k | iq2000 \
| m32c | m32r | m32rle | m68000 | m68k | m88k \
| maxq | mb | microblaze | mcore \
| maxq | mb | microblaze | mcore | mep \
| mips | mipsbe | mipseb | mipsel | mipsle \
| mips16 \
| mips64 | mips64el \
@ -324,7 +324,7 @@ case $basic_machine in
| clipper-* | craynv-* | cydra-* \
| d10v-* | d30v-* | dlx-* \
| elxsi-* \
| f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \
| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
| h8300-* | h8500-* \
| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
| i*86-* | i860-* | i960-* | ia64-* \
@ -925,6 +925,9 @@ case $basic_machine in
basic_machine=sh-hitachi
os=-hms
;;
sh5el)
basic_machine=sh5le-unknown
;;
sh64)
basic_machine=sh64-unknown
;;
@ -1219,7 +1222,7 @@ case $os in
| -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
| -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
| -skyos* | -haiku* | -rdos* | -toppers*)
| -skyos* | -haiku* | -rdos* | -toppers* | -drops*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-qnx*)
@ -1414,6 +1417,9 @@ case $basic_machine in
m68*-cisco)
os=-aout
;;
mep-*)
os=-elf
;;
mips*-cisco)
os=-elf
;;