Skip to content

Instantly share code, notes, and snippets.

@mattn
Created January 31, 2011 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/804475 to your computer and use it in GitHub Desktop.
Save mattn/804475 to your computer and use it in GitHub Desktop.
APACHE_ROOT=C:\Program Files\Apache Software Foundation\Apache2.2
RUBY_ROOT=C:\Ruby
SRCS = \
apache_cookie.c \
apache_multipart_buffer.c \
apache_request.c \
apachelib.c \
array_header.c \
bucket.c \
connection.c \
cookie.c \
error.c \
mod_ruby.c \
multival.c \
paramtable.c \
request.c \
ruby_config.c \
ruby_shared_stub.c \
server.c \
table.c \
upload.c \
uri.c
OBJS = $(SRCS:.c=.o)
CFLAGS=-I"$(APACHE_ROOT)\include" -I"$(RUBY_ROOT)\lib\ruby\1.8\i386-mswin32" -DWIN32
LDFLAGS=-L"$(APACHE_ROOT)\lib" -L"$(RUBY_ROOT)\lib"
LIBS= -llibapr-1.lib -llibaprutil-1.lib -llibhttpd.lib -lmsvcrt-ruby18.lib
.SUFFIXES: .c .o
all : mod_ruby.so
.c.o:
gcc -c $(CFLAGS) -o $@ $<
mod_ruby.so : $(OBJS)
gcc -shared -o $@ $(OBJS) $(LDFLAGS) $(LIBS)
clean :
-@rm -f *.o *.so
@zdavatz
Copy link

zdavatz commented Feb 1, 2011

It almost worked, I still get the following error:

C:\Users\zdavatz\software\mod_ruby>make
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o apache_cookie.o apache_cookie.c
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o apache_multipart_buffer.o apache_multipart_buffer.c
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o apache_request.o apache_request.c
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o apachelib.o apachelib.c
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o array_header.o array_header.c
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o bucket.o bucket.c
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o connection.o connection.c
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o cookie.o cookie.c
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o error.o error.c
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o mod_ruby.o mod_ruby.c
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o multival.o multival.c
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o paramtable.o paramtable.c
gcc -c -I"C:\Apache2.2\include" -I"C:\Ruby-1.8.6-oniguruma\lib\ruby\1.8\i386-mingw32" -DWIN32 -o request.o request.c
request.c:794:13: error: conflicting types for 'mode_t'
c:\mingw\bin../lib/gcc/mingw32/4.5.0/../../../../include/sys/types.h:99:17: note: previous declaration of 'mode_t' was here
request.c: In function 'request_finfo':
request.c:877:17: warning: assignment makes integer from pointer without a cast
request.c:878:17: warning: assignment makes integer from pointer without a cast
request.c: In function 'request_send_fd':
request.c:1580:5: warning: passing argument 2 of 'apr_os_file_put' from incompatible pointer type
C:\Apache2.2\include/apr_portable.h:340:27: note: expected 'void *' but argument is of type 'int *'
make: *
* [request.o] Error 1

Any hints?

Best
Zeno

@zdavatz
Copy link

zdavatz commented Feb 1, 2011

If I comment out

//typedef int mode_t;

in request.c (line 794)

then I get the following errors:

gcc.exe: libapr-1.lib: No such file or directory
gcc.exe: libaprutil-1.lib: No such file or directory
gcc.exe: libhttpd.lib: No such file or directory
gcc.exe: msvcrt-ruby18.lib: No such file or directory
make: *** [mod_ruby.so] Error 1

But the files are there. Is this a Makefile problem?

Best
Zeno

@zdavatz
Copy link

zdavatz commented Feb 1, 2011

If I modify the the Makefile more to leaving away the .lib at the end of the filenames

LIBS= -llibapr-1 -llibaprutil-1 -llibhttpd -lmsvcrt-ruby18

I get:

apache_request.o:apache_request.c:(.text+0x1815): undefined reference to `_imp__apr_month_snames'

apache_request.o:apache_request.c:(.text+0x1831): undefined reference to `_imp__apr_day_snames'

apachelib.o:apachelib.c:(.text+0x33a): undefined reference to `_imp__ap_server_root'

bucket.o:bucket.c:(.text+0x111): undefined reference to `_imp__apr_bucket_type_flush'

bucket.o:bucket.c:(.text+0x156): undefined reference to `_imp__apr_bucket_type_eos'

bucket.o:bucket.c:(.text+0x19b): undefined reference to `_imp__apr_bucket_type_file'

bucket.o:bucket.c:(.text+0x1e0): undefined reference to `_imp__apr_bucket_type_pipe'

bucket.o:bucket.c:(.text+0x225): undefined reference to `_imp__apr_bucket_type_socket'

bucket.o:bucket.c:(.text+0x26a): undefined reference to `_imp__apr_bucket_type_heap'

bucket.o:bucket.c:(.text+0x2af): undefined reference to `_imp__apr_bucket_type_transient'

bucket.o:bucket.c:(.text+0x2f4): undefined reference to `_imp__apr_bucket_type_immortal'

bucket.o:bucket.c:(.text+0x339): undefined reference to `_imp__apr_bucket_type_mmap'

bucket.o:bucket.c:(.text+0x37e): undefined reference to `_imp__apr_bucket_type_pool'

mod_ruby.o:mod_ruby.c:(.text+0xcca): undefined reference to `_imp__ap_real_exit_code'

mod_ruby.o:mod_ruby.c:(.text+0xcf3): undefined reference to `_imp__ap_real_exit_code'

mod_ruby.o:mod_ruby.c:(.text+0xcfa): undefined reference to `_imp__ap_real_exit_code'

mod_ruby.o:mod_ruby.c:(.text+0xd03): undefined reference to `_imp__ap_real_exit_code'

request.o:request.c:(.text+0x30fc): undefined reference to `_imp__core_module'

request.o:request.c:(.text+0x3164): undefined reference to `_imp__core_module'

request.o:request.c:(.text+0x31b4): undefined reference to `_imp__core_module'

request.o:request.c:(.text+0x31ec): undefined reference to `_imp__core_module'

request.o:request.c:(.text+0x3254): undefined reference to `_imp__core_module'

request.o:request.c:(.text+0x32a4): more undefined references to `_imp__core_module' follow

ruby_config.o:ruby_config.c:(.text+0x9c8): undefined reference to `_imp__ap_real_exit_code'

ruby_config.o:ruby_config.c:(.text+0x9f1): undefined reference to `_imp__ap_real_exit_code'

ruby_config.o:ruby_config.c:(.text+0x9f8): undefined reference to `_imp__ap_real_exit_code'

ruby_config.o:ruby_config.c:(.text+0xa01): undefined reference to `_imp__ap_real_exit_code'

server.o:server.c:(.text+0x875): undefined reference to `_imp__core_module'

collect2: ld returned 1 exit status

make: *** [mod_ruby.so] Error 1

Best
Zeno

@mattn
Copy link
Author

mattn commented Feb 2, 2011

Would you try to specify the library file directly.

LIBS= c:/Apache2.2/lib/libapr-1.lib c:/Apache2.2/lib/llibaprutil-1.lib c:/Apache2.2/lib/libhttpd.lib -lmsvcrt-ruby18

@zdavatz
Copy link

zdavatz commented Feb 2, 2011

If I leave away the ".lib" at the end of the files it works with mingw.

LIBS= -llibapr-1 -llibaprutil-1 -llibhttpd -lmsvcrt-ruby18

It does find the libraries but I get other errors because the linkage between the .o files and the .c files does not work.

@zdavatz
Copy link

zdavatz commented Feb 2, 2011

These are the errors I get once it finds the libraries:

See all the imp_ errors. I guess this must be due to the linking of the .c to the .o files.

C:\Users\zdavatz\software\mod_ruby>make
gcc -shared -o mod_ruby.so apache_cookie.o apache_multipart_buffer.o apache_request.o apachelib.o array_header.o bucket.o connection.o cookie.o error.o mod_ruby
.o multival.o paramtable.o request.o ruby_config.o ruby_shared_stub.o server.o table.o upload.o uri.o -L"C:\Apache2.2\lib" -L"C:\Ruby-1.8.6-oniguruma\lib" -llib
apr-1 -llibaprutil-1 -llibhttpd -lmsvcrt-ruby18
apache_request.o:apache_request.c:(.text+0x1815): undefined reference to `_imp__apr_month_snames'

apache_request.o:apache_request.c:(.text+0x1831): undefined reference to `_imp__apr_day_snames'

apachelib.o:apachelib.c:(.text+0x33a): undefined reference to `_imp__ap_server_root'

bucket.o:bucket.c:(.text+0x111): undefined reference to `_imp__apr_bucket_type_flush'

bucket.o:bucket.c:(.text+0x156): undefined reference to `_imp__apr_bucket_type_eos'

bucket.o:bucket.c:(.text+0x19b): undefined reference to `_imp__apr_bucket_type_file'

bucket.o:bucket.c:(.text+0x1e0): undefined reference to `_imp__apr_bucket_type_pipe'

bucket.o:bucket.c:(.text+0x225): undefined reference to `_imp__apr_bucket_type_socket'

bucket.o:bucket.c:(.text+0x26a): undefined reference to `_imp__apr_bucket_type_heap'

bucket.o:bucket.c:(.text+0x2af): undefined reference to `_imp__apr_bucket_type_transient'

bucket.o:bucket.c:(.text+0x2f4): undefined reference to `_imp__apr_bucket_type_immortal'

bucket.o:bucket.c:(.text+0x339): undefined reference to `_imp__apr_bucket_type_mmap'

bucket.o:bucket.c:(.text+0x37e): undefined reference to `_imp__apr_bucket_type_pool'

mod_ruby.o:mod_ruby.c:(.text+0xcca): undefined reference to `_imp__ap_real_exit_code'

mod_ruby.o:mod_ruby.c:(.text+0xcf3): undefined reference to `_imp__ap_real_exit_code'

mod_ruby.o:mod_ruby.c:(.text+0xcfa): undefined reference to `_imp__ap_real_exit_code'

mod_ruby.o:mod_ruby.c:(.text+0xd03): undefined reference to `_imp__ap_real_exit_code'

request.o:request.c:(.text+0x30fc): undefined reference to `_imp__core_module'

request.o:request.c:(.text+0x3164): undefined reference to `_imp__core_module'

request.o:request.c:(.text+0x31b4): undefined reference to `_imp__core_module'

request.o:request.c:(.text+0x31ec): undefined reference to `_imp__core_module'

request.o:request.c:(.text+0x3254): undefined reference to `_imp__core_module'

request.o:request.c:(.text+0x32a4): more undefined references to `_imp__core_module' follow

ruby_config.o:ruby_config.c:(.text+0x9c8): undefined reference to `_imp__ap_real_exit_code'

ruby_config.o:ruby_config.c:(.text+0x9f1): undefined reference to `_imp__ap_real_exit_code'

ruby_config.o:ruby_config.c:(.text+0x9f8): undefined reference to `_imp__ap_real_exit_code'

ruby_config.o:ruby_config.c:(.text+0xa01): undefined reference to `_imp__ap_real_exit_code'

server.o:server.c:(.text+0x875): undefined reference to `_imp__core_module'

collect2: ld returned 1 exit status

make: *** [mod_ruby.so] Error 1

@zdavatz
Copy link

zdavatz commented Feb 2, 2011

With these

LIBS= C:/Apache2.2/lib/libapr-1.lib C:/Apache2.2/lib/libaprutil-1.lib C:/Apache2.2/lib/libhttpd.lib -lmsvcrt-ruby18

I get the same error as above, that is a lot of "undefined reference to" errors. These must be connected to some linkage problem between the .o and the .c files.

i.e.: mod_ruby.o:mod_ruby.c:(.text+0xcf3): undefined reference to

@zdavatz
Copy link

zdavatz commented Feb 2, 2011

Your nmake links against the DLL of Apache, correct? The DLLs of Apache on Windows are all placed in the bin Directory of Apache so I guess MinGW has to link against those DLLs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment