Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DLL Build #63

Open
gAndy50 opened this issue Jul 24, 2024 · 14 comments
Open

DLL Build #63

gAndy50 opened this issue Jul 24, 2024 · 14 comments

Comments

@gAndy50
Copy link

gAndy50 commented Jul 24, 2024

Is it possible to build TIGR as a DLL or shared library?

@JettMonstersGoBoom
Copy link

https://github.com/JettMonstersGoBoom/tigr I have an example "examples/hellodll" for building TIGR as a DLL. just changes to the tigr.h file. and some compile flags.
I haven't tested on OSX or Linux though. it "should" work.

@gAndy50
Copy link
Author

gAndy50 commented Jul 28, 2024

Thanks. I tried to build it, but I keep getting __mingw_winmain undefined reference error. I'm trying to build it under Windows.

@JettMonstersGoBoom
Copy link

that's odd. I'm using x86_64-w64-mingw32 version 13.2.0.
to double check I didn't miss anything, I completely removed the archive from my machine and pulled that version, it compiled with makefile there ?

@gAndy50
Copy link
Author

gAndy50 commented Jul 28, 2024

When I do this:
gcc -c tigr.c - It compiles fine (It works fine using mingw32-make as well)
But when I do this:
gcc -shared -o tigr.dll tigr.o - it comes up with the __ming_winmain errors.

@JettMonstersGoBoom
Copy link

JettMonstersGoBoom commented Jul 28, 2024

-DTIGR_BUILDSHARED is needed for the DLL,
-DTIGR_SHARED is needed for the executable that references it.
please see the makefile provided.

@gAndy50
Copy link
Author

gAndy50 commented Jul 28, 2024

Alright, I think I almost got it.
I did mingw32-make, it outputs this:
gcc ../../tigr.c -DTIGR_BUILDSHARED -shared -I../.. -Os -s -DTIGR_SHARED -s -lopengl32 -lgdi32 -o tigr.dll
But these errors appear:
undefined reference to `__mingw_winmain_hInstance

@JettMonstersGoBoom
Copy link

JettMonstersGoBoom commented Jul 28, 2024

that error when building the DLL ? I'm not really sure what's going on there. did you clean any .o or .dll files first ?

@gAndy50
Copy link
Author

gAndy50 commented Jul 28, 2024

I can't figure out why it isn't building either, I'll try a few more things.

@JettMonstersGoBoom
Copy link

JettMonstersGoBoom commented Jul 29, 2024

I just installed w64devkit and git on a clean machine and still don't have any issues ? I don't see how mingw would be different for something this trivial.

@gAndy50
Copy link
Author

gAndy50 commented Jul 29, 2024

I figured it out. The error was coming from the WinMain function. To build a DLL, you don't need a Winmain function.

add to line 2699 in tigr.c #ifndef TIGR_BUILDSHARED
add to line 2724 in tigr. c #endif

--begin of makefile
CFLAGS += -Os -s
LDFLAGS += -shared
ifeq ($(OS),Windows_NT)
CFLAGS += -DTIGR_SHARED
LDLIBS += -lopengl32 -lgdi32
LIBEXT := .dll
else
CFLAGS += -fPIC
LIBPRE := lib
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LDLIBS += -framework OpenGL -framework Cocoa
LIBEXT := .dylib
else
LDLIBS += -lGLU -lGL -lX11
LIBEXT := .so
endif
endif

$(LIBPRE)tigr$(LIBEXT): tigr.c
gcc $(CFLAGS) -DTIGR_BUILDSHARED $(LDFLAGS) -o $@ $< $(LDLIBS)
-- end of make file

--build DLL or shared library
tigr.dll: tigr.c
gcc -Os -s -DTIGR_SHARED -DTIGR_BUILDSHARED -shared -o $@ $< -lopengl32 -lgdi32

Thanks to https://github.com/ghaberek for his help with this.

@JettMonstersGoBoom
Copy link

I agree you shouldn't need it, but it also shouldn't cause an issue with building and linking a dll. At least you got it resolved.

@gAndy50
Copy link
Author

gAndy50 commented Jul 29, 2024

Yes, it does seem odd, but I got it to work and have a DLL now. Thanks for your help as well.

@JettMonstersGoBoom
Copy link

added the change to my repo. just incase someone else runs into this.

@gAndy50
Copy link
Author

gAndy50 commented Jul 31, 2024

Sounds good. I've made a wrapper for the TIGR library for OpenEuphoria. https://github.com/gAndy50/EuTigr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants