How to build a library with tcc using Windows? - c

I'm currently trying to use the gumbo-parser library with TCC compiler on Windows.
https://github.com/google/gumbo-parser
There are no library files included so I tried to create them by myself.
I was able to compile the get_tile.c demo by referencing all the library .o files manually, however i want to create a singe library (.so/.a/.dll) file.
I tried to generate a .dll by using tcc -shared *.c but when I try to create a .def file by using tiny_impdef I get the following error:
tiny_impdef: could not get exported function names.
I also tried to create a .a file by using:
> tiny_libmaker attribute.o char_ref.o error.o parser.o string_buffer.o string_piece.o tag.o tokenizer.o utf8.o util.o vector.o
But when I try to reference it, it looks like it won't get recognized:
> tcc -Isrc -Lsrc examples\get_title.c
tcc: error: undefined symbol 'kGumboDefaultOptions'
tcc: error: undefined symbol 'gumbo_parse_with_options'
tcc: error: undefined symbol 'gumbo_destroy_output'
What am I doing wrong?

Related

How do I compile with zlib on windows using gcc?

My aim is to compile zlib alongside my application files, I use gcc from tdm-gcc and have cloned the repository https://github.com/madler/zlib
in /example there is a zpipe.c file which utilizes the library but I can't seem to get it compiling on windows.
I've added -lz to the end of my compile command and I receive /x86_64-w64-mingw32/bin/ld.exe: cannot find -lz error.
If I try to compile with just -Izlib I end up with these errors:
$ gcc -Izlib zpipe.c -o zpipe
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[redacted]\AppData\Local\Temp\ccjXicsi.o:zpipe.c:(.text+0x6a): undefined reference to `deflateInit_'
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[redacted]\AppData\Local\Temp\ccjXicsi.o:zpipe.c:(.text+0xca): undefined reference to `deflateEnd'
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[redacted]\AppData\Local\Temp\ccjXicsi.o:zpipe.c:(.text+0x12e): undefined reference to `deflate'
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[redacted]\AppData\Local\Temp\ccjXicsi.o:zpipe.c:(.text+0x1be): undefined reference to `deflateEnd'
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[redacted]\AppData\Local\Temp\ccjXicsi.o:zpipe.c:(.text+0x23c): undefined reference to `deflateEnd'
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[redacted]\AppData\Local\Temp\ccjXicsi.o:zpipe.c:(.text+0x2c0): undefined reference to `inflateInit_'
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[redacted]\AppData\Local\Temp\ccjXicsi.o:zpipe.c:(.text+0x320): undefined reference to `inflateEnd'
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[redacted]\AppData\Local\Temp\ccjXicsi.o:zpipe.c:(.text+0x36f): undefined reference to `inflate'
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[redacted]\AppData\Local\Temp\ccjXicsi.o:zpipe.c:(.text+0x3d1): undefined reference to `inflateEnd'
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[redacted]\AppData\Local\Temp\ccjXicsi.o:zpipe.c:(.text+0x440): undefined reference to `inflateEnd'
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\[redacted]\AppData\Local\Temp\ccjXicsi.o:zpipe.c:(.text+0x474): undefined reference to `inflateEnd'
collect2.exe: error: ld returned 1 exit status
Any help is greatly appreciated! I've searched stack overflow and tried all the suggestions and also googled and I'm still having issues.
The errors seem trivial and I've fixed such errors in the past, but this one I'm stuck on and I'm not sure what else to try.
1) Creating the static library.
Inside the zlib folder where the .c and .h files are located running gcc -c *.c will generate .o files that can be used to build the library.
after you have the .o files, running ar -rc libz.a *.o will generate a libz.a file, this will allow you to link via -lz
2) Compiling zpipe.c into zpipe.exe
put zpipe.c into the folder where libz.a is located, this is for simplicity when compiling.
running gcc -L. zpipe.c -o zpipe.exe -lz will create zpipe.exe.
3) Quick demo
Create a file hello.txt with Hello World! inside.
Run ./zpipe.exe < hello.txt > output.txt this will inflate the data in hello.txt and put it in output.txt
Run ./zpipe.exe -d < output.txt > original.txt to decompress the file and you will see Hello World! inside original.txt
Definitions
-L. tells gcc to use the current folder for the header files.
-lz tells gcc to compile with a static library who's name starts with lib and ends in .a for eg. libexample.a would be -lexample
When using MSYS2 shell it's quite simple, just run the following commands (replace /usr/local with the desired location):
INSTALLPREFIX=/usr/local
wget -c http://www.zlib.net/zlib-1.2.12.tar.gz
tar xfz zlib-1.2.12.tar.gz
cd zlib-1.2.12
make -f win32/Makefile.gcc install \
SHARED_MODE=1 \
INCLUDE_PATH=$INSTALLPREFIX/include \
LIBRARY_PATH=$INSTALLPREFIX/lib \
BINARY_PATH=$INSTALLPREFIX/bin

GCC Undefined reference. Cannot locate Library

So i'm trying to create .so files for use in the ctypes library for python but am running into a bit of a snag.
The files in the directory are cbw.h, cbw64.lib, and Main.c
During my attempt of creating the .so file using the following command string in Windows Powershell:
gcc -shared -o testlib.so -fPIC Main.C -lcbw
I get the error 'cannot find -lcbw'.
I put this in, because if I don't, I get that there are 'undefined references' in Main.C which were defined during the 'include cbw.h' line in Main.c
What is wrong with my command? I am able to create a .so file if I use a simple program like Hello world but cannot do so as soon as I try to import predefined functions.
edit:
If i use the object library cbw64.lib I get the error, ' error adding symbols: file in wrong format'

Can't link against WinPcap library wpcap.lib ("undefined reference to")

I am trying to build an example program which uses WinPcap-functions. I’m working under Windows 7 64 Bit edition with MinGW. I am able to compile the C-code to an object file, but I can’t link against wpcap.lib.
My linker call looks like this:
gcc -L ../../lib/x64 send_packet.o -lwpcap -o WinPcapTest.exe
With this call I get the following errors:
undefined reference to pcap_open
undefined reference to pcap_sendpacket
undefined reference to pcap_geterr
Obviously I am not linking against wpcap.lib, but I don’t know why. The library is definitely found. If I change the lib include path for example, I get this error:
cannot find -lwpcap
Why does the linker find the lib but does not link against it? Thanks for your help.
Try listing you libraries after binary definition. As far as I remember, with provided gcc command, ld would be symbol matching for pcap symbols between send_packet.o and libwpcap.lib but not with WinPcapTest.exe. I would suggest moving -lwpcap at the end:
gcc -I ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Include ..\send_packet.c -L ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Lib\x64 -O0 -g3 -Wall -o WinPcapTest.exe -lwpcap

Compiling a c application that links to a static library on AIX

I'm trying to compile my application to link to a static library (.a file)
The command I use to build is this:
gcc -DUNIX -maix32 -o Release/bin/testApp Release/obj/main.o -ltestLib
When I build I get the following errors:
ld: 0711-317 ERROR: Undefined symbol: .test
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
Where test is a method in libtestLib.a
Also if I try and build with a dynamic lib then it is successful.
gcc -DUNIX -maix32 -o Release/bin/testApp Release/obj/main.o libtestLib.so
Can you see where I am going wrong?
Can you try specifying a path to the archive file, rather than -ltestLib?
gcc -DUNIX -maix32 /path/to/testLib.a -o Release/bin/testApp Release/obj/main.o

Undefined reference to t1sl_steup_key_block when linking OpenSSL

I got a problem of linking an OpenSSL library into an existing project.
Where I do get it wrong?
Below are the steps I have followed.
I have downloaded the SSL library, configured and installed it. It gets installed in /usr/local/ssl.
2) I have copied libcrypto.a and libssl.a from /usr/local/ssl/lib into my project, something like /mnt/linux/bla/bla/lib.
3) Then I edit the make file and added path of libssl libcrpto there. The path added is one that is in project like /mnt/linux/bla /bla
3) make
4) build project via slick edit
When it builds I get a long error chain, like
../lib/libssl.a(t1_enc.o) :In function 't1sl_steup_key_block: undefined ref
Now, I guess copying .a files into project could be problem. Is there is any alternative for that or should I use ln -s to link .a files form /usr/local/openssl/lib into my project library folder? Below is the error.
Debug/FC5/m2pa.o -ldl -lpthread -ltdapi ../septel/gctlib.lib ../lib/libpq.a ../asn1/lib/libasn1per.a ../mysql/lib/libmysqlclient.a -L../lib ../asn1/lib/libasn1rt.a -lm -lcrypt -lcrypto -lssl -rdynamic
../lib/libssl.a(ssl_lib.o): In function `SSL_set_quiet_shutdown':ssl_lib.c:(.text+0x670): multiple definition of `SSL_set_quiet_shutdown'
../mysql/lib/libmysqlclient.a(ssl.o):ssl.cpp:(.text+0x125c): first defined here
/usr/bin/ld: Warning: size of symbol `SSL_set_quiet_shutdown' changed from 45 in ../mysql/lib/libmysqlclient.a(ssl.o) to 12 in ../lib/libssl.a(ssl_lib.o)
../lib/libssl.a(ssl_lib.o): In function `SSL_get_quiet_shutdown':ssl_lib.c:(.text+0x680): multiple definition of `SSL_get_quiet_shutdown'
../mysql/lib/libmysqlclient.a(ssl.o):ssl.cpp:(.text+0x12down' changed from 35 in ../mysql/lib/libmysqlclient.a(ssl.o) to 8 in ../lib/libssl.a(ssl_lib.o)
../lib/libssl.a(ssl_err2.o): In function `SSL_load_error_strings':ssl_err2.c:(.text+0x4): undefined reference to `ERR_load_crypto_strings'
../lib/libssl.a(ssl_algs.o): In function `SSL_library_init':ssl_algs.c:(.text+0x4): undefined reference to `EVP_des_cbc'
:ssl_algs.c:(.text+0xc): undefined reference to `EVP_add_cipher'
:ssl_algs.c:(.text+0x11): undefined reference to `EVP_des_ede3_cbc'
:ssl_algs.c:(.text+0x19): undefined reference to `EVP_add_cipher'
:ssl_algs.c:(.text+0x1e): undefined reference to `EVP_idea_cbc'
Have you tried using the libssl and libcrypto already installed in your /usr/lib directory (assuming you've installed the dev packages for both)? Once that compiles and runs without error using the default install, you can build your new libssl/libcrypto(?) from source, install to usr/local, and rebuild using the usr/local versions of the libraries.
You need to add the flag -lssl and -lcrypto in your makefile'
For example:
gcc somefile.c -o someprogram -lssl -lcrypto

Resources