Discussion:
[Tinycc-devel] How to link...?
Lostgallifreyan
2012-02-13 10:39:02 UTC
Permalink
I recently started using TCC again, first time in over a year. I got a couple of small power-saving programs working (monitor and disk motor shutdown), then got ambitious and have fallen flat....

To use MIDI I need to link libwinmm.a from the GCC compiler (or winmm.lib from VC++). No matter what I try (having Googled for two days), I get the same errors every time, undefined symbols. Can TCC link these files at all, and if so, exactly how do I do it? (Using W98 SE).

My last effort:

@ECHO OFF
PATH=%PATH%;E:\CODING\TCC
TCC.EXE C:\WINDOWS\DESKTOP\TEST\MIDI.c -LE:\Coding\tcc\lib\libwinmm.a -oC:\WINDOWS\DESKTOP\TEST\MIDI.exe

The C code was found online, as far as I know, all I had to do was add a line to it as follows, just after any include lines.
#pragma comment(lib,"libwinmm.a")


Results:
tcc: undefined symbol '***@12'
tcc: undefined symbol '***@20'
tcc: undefined symbol '***@8'
tcc: undefined symbol '***@4'
Lostgallifreyan
2012-02-13 11:58:45 UTC
Permalink
Small bit of extra info:
This compiles and links ok using GCC in W98 SE:
C:\PROGRA~1\DEV-CPP\BIN\GCC.EXE -IC:\Progra~1\Dev-Cpp\include -mwindows C:\WINDOWS\DESKTOP\TEST\MIDI.c E:\Coding\tcc\lib\libwinmm.a -oC:\WINDOWS\DESKTOP\TEST\MIDI.exe


I didn't even need the pragma bit added to the source code to make it work, so I don't know why TCC isn't working. A quick look at libtcc1.a and GCC's libwinmm.a using a hex editor show enough similarity of internal formatting, that I infer there's no incompatibility in the file, but the various errors I get inlude "invalid object file" or "tcc: file '/lE:\Coding\tcc\lib\libwinmm.a' not found", or the undefined symbols I mentioned in the first mail, depending on what switches I try or omit.

Basically, nothing works, and I tried plenty. If I hadn't managed to make it in GCC, I'd assume user error, but I now suspect something else. if it IS user error, please be kind to me and spell out all the required detail, because if it's a chain of AND logic, it only takes ONE error in the chain, and I have no way to trust the rest.
Lostgallifreyan
2012-02-14 17:42:56 UTC
Permalink
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib,"libwinmm.a")

HMIDIOUT H_device;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
BYTE A[4]={0x90,61,78,0};
midiOutOpen(&H_device,(UINT)-1,0,0,CALLBACK_NULL);
midiOutShortMsg(H_device,*(DWORD*)A);
Sleep(1000);
A[2]=0;
midiOutShortMsg(H_device,*(DWORD*)A);
midiOutClose(H_device);
return 0;
}


DOS Batch file:
@ECHO OFF
PATH=%PATH%;E:\CODING\TCC
TCC.EXE C:\WINDOWS\DESKTOP\TEST\TEST2.c -LE:\Coding\tcc\lib\libwinmm.a -oC:\WINDOWS\DESKTOP\TEST\TEST.exe

This fails with undefined-symbol errors, even though libwinmm.a is provided, copied from GCC. Why? GCC will link libwinmm.a and compile this code, and it runs ok.
Also, is that #pragma line needed? GCC doesn't need it, but plenty of coders seem to think it's required.

Please help. I really want to use TCC for this as first choice, as I like it best out of all compilers I have tried.
Lostgallifreyan
2012-02-16 19:45:56 UTC
Permalink
Well, I was very kindly answered by 'nobody' (and myself a couple of times) but nobody didn't have anything to say so I eventually found a way myself.

In case anyone comes by wanting the answer, it's this:
tiny_impdef.exe C:/Windows/System/Winmm.dll
(tiny_impdef.exe is supplied with TCC)
Put the resulting WINMM.DEF file into the TCC's lib directory. After which this works:

TCC.EXE C:\WINDOWS\DESKTOP\TEST\MIDI.c -lwinmm -oC:\WINDOWS\DESKTOP\TEST\MIDI.exe

(Do not use '-Lwinmm.def', use LOWER case -l, and omit the .def bit or it still borks.)

I still don't know why we can't do it with the same command we'd use for GCC, but it this price of inconvenience pays for the ability to fetch definitions from ANY dll file so we can call its functions for code compiled with TCC, it's a neat idea that I can live with.
Milutin Jovanović
2012-02-17 02:40:54 UTC
Permalink
I am glad to see you found a solution. As you can see this is not the most
active of projects/mailing lists, so it is a hit and miss. I am sure
somebody would have answered if they knew. Thank you for posting your
solution here. It will surely help someone who searches for this in the
future.

Miki.
Post by Lostgallifreyan
Well, I was very kindly answered by 'nobody' (and myself a couple of
times) but nobody didn't have anything to say so I eventually found a way
myself.
tiny_impdef.exe C:/Windows/System/Winmm.dll
(tiny_impdef.exe is supplied with TCC)
TCC.EXE C:\WINDOWS\DESKTOP\TEST\MIDI.c -lwinmm
-oC:\WINDOWS\DESKTOP\TEST\MIDI.exe
(Do not use '-Lwinmm.def', use LOWER case -l, and omit the .def bit or it still borks.)
I still don't know why we can't do it with the same command we'd use for
GCC, but it this price of inconvenience pays for the ability to fetch
definitions from ANY dll file so we can call its functions for code
compiled with TCC, it's a neat idea that I can live with.
_______________________________________________
Tinycc-devel mailing list
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
--
Miki.
Lostgallifreyan
2012-02-17 04:56:13 UTC
Permalink
Indeed. I like TCC so I want to help keep the faith. Sometimes I really might need the answer even after weeks of fumbling around, so if I can help spare anyone that it might increase my chances too. I don't know enough to contribute much more. :)

Milutin_Jovanovic <***@gmail.com> wrote:
(17/02/2012 02:40)
Post by Milutin Jovanović
I am glad to see you found a solution. As you can see this is not the most
active of projects/mailing lists, so it is a hit and miss. I am sure
somebody would have answered if they knew. Thank you for posting your
solution here. It will surely help someone who searches for this in the
future.
Miki.
Post by Lostgallifreyan
Well, I was very kindly answered by 'nobody' (and myself a couple of
times) but nobody didn't have anything to say so I eventually found a way
myself.
tiny_impdef.exe C:/Windows/System/Winmm.dll
(tiny_impdef.exe is supplied with TCC)
TCC.EXE C:\WINDOWS\DESKTOP\TEST\MIDI.c -lwinmm
-oC:\WINDOWS\DESKTOP\TEST\MIDI.exe
(Do not use '-Lwinmm.def', use LOWER case -l, and omit the .def bit or it still borks.)
I still don't know why we can't do it with the same command we'd use for
GCC, but it this price of inconvenience pays for the ability to fetch
definitions from ANY dll file so we can call its functions for code
compiled with TCC, it's a neat idea that I can live with.
_______________________________________________
Tinycc-devel mailing list
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
--
Miki.
Continue reading on narkive:
Loading...