Mail Archives: cygwin/2000/10/09/19:47:21
You still need to worry about things like __declspec(dllexport) and
__declspec(dllimport). Here's a patch for your files.
(Yes, you are correct; the option is '--export-all-symbols' not
'--export-all')
As far as documentation, there's the mailing list, and 'ld --help' and
Mumit's (really out-of-date) dll-helpers packaqe at
http://www.xraylith.wisc.edu/~khan/software/gnu-win32/dllhelpers.html.
Would you like to update that package for the current capabilities of
ld/gcc ? Mumit's tutorial is heavily 'dlltool' based, rather than 'gcc
-shared' or 'ld' based.
NOTE 1: I had to remove "-Wl,--export-all-symbols" from the options;
with export-all I got a stack dump even with my other changes. I'm not
sure why.
NOTE 2: I used the extension '.dll.a' for the import library; cygwin's
linker will search for 'libfoo.dll.a' in preference to 'libfoo.a';
libfoo.a is assumed to be a static library (although the linker will use
libfoo.a if .dll.a is not found)
--Chuck
diff -u demo-orig/Makefile demo/Makefile
--- demo-orig/Makefile Mon Oct 9 19:34:15 2000
+++ demo/Makefile Mon Oct 9 19:45:10 2000
@@ -3,7 +3,7 @@
EXENAME = demo
EXEOBJ = demo.o
CPLUS = g++ -W -Wall -Werror
-LINKDLL = g++ -shared -Wl,--export-all -Wl,--enable-auto-image-base
+LINKDLL = g++ -shared -Wl,--enable-auto-image-base
LINKEXE = g++ -L.
.DELETE_ON_ERROR:
@@ -13,13 +13,16 @@
all: $(DLLNAME).dll $(EXENAME)
clean:
- rm -f $(DLLOBJ) $(DLLNAME).dll lib$(DLLNAME).a $(EXEOBJ)
$(EXENAME).exe
+ rm -f $(DLLOBJ) $(DLLNAME).dll lib$(DLLNAME).dll.a $(EXEOBJ)
$(EXENAME).exe
%.o: %.cpp
$(CPLUS) -c $< -o $@
+$(DLLOBJ): $(DLLOBJ:.o=.cpp)
+ $(CPLUS) -DBUILD_DLL -c $< -o $@
+
$(DLLNAME).dll: $(DLLOBJ)
- $(LINKDLL) $(DLLOBJ) -o $(DLLNAME).dll
-Wl,--out-implib=lib$(DLLNAME).a
+ $(LINKDLL) $(DLLOBJ) -o $(DLLNAME).dll
-Wl,--out-implib=lib$(DLLNAME).dll.a
$(EXENAME): $(EXEOBJ) $(DLLNAME).dll
$(LINKEXE) $(EXEOBJ) -l$(DLLNAME) -o $(EXENAME)
diff -u demo-orig/foo.hpp demo/foo.hpp
--- demo-orig/foo.hpp Mon Oct 9 19:35:58 2000
+++ demo/foo.hpp Mon Oct 9 19:35:50 2000
@@ -3,7 +3,12 @@
#include <string>
-extern std::string global_mangle(const std::string& source);
-
+#ifdef BUILD_DLL
+#define FOO_EXPORT __declspec(dllexport)
+#else
+#define FOO_EXPORT __declspec(dllimport)
#endif
+extern FOO_EXPORT std::string global_mangle(const std::string& source);
+
+#endif
Ross Smith wrote:
>
> "Charles S. Wilson" wrote:
> >
> > There's an easier way -- one command! 'gcc -shared' will create a dll
> > for you. Just do:
> >
> > $(BASE)=foo
> >
> > gcc -shared -o cyg$(BASE).dll -Wl,--out-implib=lib$(BASE).dll.a \
> > -Wl,--export-all -Wl,--enable-auto-image-base \
> > -Wl,--output-def=cyg$(BASE).def $(OBJS)
>
> I can't get this to work. Whenever I link with the import lib produced
> this way, the resulting program crashes with a STATUS_ACCESS_VIOLATION.
> (See attached code.) I don't even need to call any of the DLL functions
> to trigger it -- just linking with -lfoo makes it unworkable. What am I
> doing wrong?
>
> And where is all this stuff documented anyway? The ld docs mention
> --export-all-symbols (not --export-all), but not any of the others.
>
> -------------------- cut here --------------------
>
> // demo.cpp
>
> #include "foo.hpp"
> #include <iostream>
> #include <string>
>
> int main() {
> std::string thing("thing");
> std::cout << thing << std::endl;
> // std::cout << global_mangle(thing) << std::endl;
> return 0;
> }
>
> -------------------- cut here --------------------
>
> // foo.hpp
>
> #ifndef FOO_HEADER
> #define FOO_HEADER
>
> #include <string>
>
> extern std::string global_mangle(const std::string& source);
>
> #endif
>
> -------------------- cut here --------------------
>
> // foo.cpp
>
> #include "foo.hpp"
>
> std::string global_mangle(const std::string& source) {
> return source + "_global";
> }
>
> -------------------- cut here --------------------
>
> // Makefile
>
> DLLNAME = foo
> DLLOBJ = foo.o
> EXENAME = demo
> EXEOBJ = demo.o
> CPLUS = g++ -W -Wall -Werror
> LINKDLL = g++ -shared -Wl,--export-all -Wl,--enable-auto-image-base
> LINKEXE = g++ -L.
>
> .DELETE_ON_ERROR:
>
> .PHONY: all clean
>
> all: $(DLLNAME).dll $(EXENAME)
>
> clean:
> rm -f $(DLLOBJ) $(DLLNAME).dll lib$(DLLNAME).a $(EXEOBJ)
> $(EXENAME).exe
>
> %.o: %.cpp
> $(CPLUS) -c $< -o $@
>
> $(DLLNAME).dll: $(DLLOBJ)
> $(LINKDLL) $(DLLOBJ) -o $(DLLNAME).dll
> -Wl,--out-implib=lib$(DLLNAME).a
>
> $(EXENAME): $(EXEOBJ) $(DLLNAME).dll
> $(LINKEXE) $(EXEOBJ) -l$(DLLNAME) -o $(EXENAME)
>
> demo.o: demo.cpp foo.hpp
> foo.o: foo.cpp foo.hpp
>
> -------------------- cut here --------------------
>
> --
> Ross Smith <ross DOT s AT ihug DOT co DOT nz> The Internet Group, Auckland, New Zealand
> ========================================================================
> "C++ is to programming as sex is to reproduction. Better ways might
> technically exist but they're not nearly as much fun." -- Nikolai Irgens
>
> --
> Want to unsubscribe from this list?
> Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com
- Raw text -