-5

I am trying to compile a library, but keep getting these errors. Not too familiar with C and don't know how to get around this. It doesn't create the dll.

c:\>C:\tcc\tcc.exe C:\tcc\examples\hello_dll.c -o C:\tcc\examples\test_win.dll
tcc: error: undefined symbol 'hello_data'
tcc: error: undefined symbol 'hello_func'
//+---------------------------------------------------------------------------
//
//  HELLO_DLL.C - Windows DLL example - main application part
//

#include <windows.h>

void hello_func (void);
__declspec(dllimport) extern const char *hello_data;

int WINAPI WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR     lpCmdLine,
    int       nCmdShow)
{
hello_data = "Hello World!";
hello_func();
return 0;
}
melpomene
  • 84,125
  • 8
  • 85
  • 148
William
  • 1
  • 1
  • That's not a library. That's an application. – melpomene Oct 20 '18 at 20:32
  • There are several problems here. That's an application, not a dll, you're not passing the right command line flags for a Windows subsystem program, and since you're trying to link in some external symbols you need to actually provide the library or obj with those symbols. You'll likely have better results if you learn how to do these things before you try to fumble your way through them. – Retired Ninja Oct 20 '18 at 20:38
  • 1
    If you are trying to learn c, you should concentrate on plain console applications with a standard `int main(int, char **)` entry point. Leave GUI programming until a point when you feel comfortable with the language. Oh, and find a newer compiler than tcc – HAL9000 Oct 20 '18 at 21:04

1 Answers1

0

Two errors:

  1. The hello_data variable is declared extern which means it is not defined in this program module so needs to come from somewhere else, from somewhere else that is linked in at the same time.
  2. Your WinMain routine calls the hello_func but it is not defined. In C, when you see the definition ending with (); that means this is a prototype to tell the compiler what to expect, not the actual code for the function.

I would suggest that to start, you plan on getting a console type application going to start, such as the infamous hello world, something like:

#include <stdio.h>
int main()
{
    printf("Hello William\n");
}

This would be compiled and run in a cmd window under MS Windows. When you get that working, you can look into doing something fancier using the windows environment and things like WinMain in a DLL.

user1683793
  • 1,213
  • 13
  • 18