0

I am using SIGIL for C++ and am having an issue where every function call to a SIGIL function given an undefined reference error. I am using the example program, here is a copy of it:

#include "sl.h"

int main(int args, char *argv[])
{
  // set up our window and a few resources we need
  slWindow(400, 400, "Simple SIGIL Example", false);
  slSetFont(slLoadFont("ttf/white_rabbit.ttf"), 24);
  slSetTextAlign(SL_ALIGN_CENTER);
  int tex = slLoadTexture("png/glow.png");

  while(!slShouldClose() && !slGetKey(SL_KEY_ESCAPE))
  {
    // background glow
    slSetForeColor(0.1, 0.9, 0.2, 0.4);
    slSprite(tex, 200, 240, 300, 200);

    // large text and fat line
    slSetForeColor(0.0, 0.8, 0.2, 1.0);
    slSetFontSize(24);
    slText(200, 250, "SIGIL:");
    slRectangleFill(200, 240, 100, 7);

    // smaller subtext
    slSetFontSize(14);
    slText(200, 220, "Sprites, text, sound, input, and more!");
    slLine(48, 210, 352, 210);

    slRender();    // draw everything
  }
  slClose();       // close the window and shut down SIGIL
  return 0;
}

Here is the build log:


-------------- Build: Debug in Puzzle Fusion (compiler: GNU GCC Compiler)---------------

g++.exe -Wall -g -Iinclude -Ibin -c "C:\Users\Ninji2701\Desktop\Pile-o-Stuff\Puzzle Fusion\main.cpp" -o obj\Debug\main.o
g++.exe -Llib -o "bin\Debug\Puzzle Fusion.exe" obj\Debug\main.o   lib\libsigil.dll.a
obj\Debug\main.o: In function `main':
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:6: undefined reference to `slWindow'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:7: undefined reference to `slLoadFont'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:7: undefined reference to `slSetFont'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:8: undefined reference to `slSetTextAlign'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:9: undefined reference to `slLoadTexture'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:11: undefined reference to `slShouldClose'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:11: undefined reference to `slGetKey'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:14: undefined reference to `slSetForeColor'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:15: undefined reference to `slSprite'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:18: undefined reference to `slSetForeColor'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:19: undefined reference to `slSetFontSize'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:20: undefined reference to `slText'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:21: undefined reference to `slRectangleFill'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:24: undefined reference to `slSetFontSize'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:25: undefined reference to `slText'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:26: undefined reference to `slLine'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:28: undefined reference to `slRender'
C:/Users/Ninji2701/Desktop/Pile-o-Stuff/Puzzle Fusion/main.cpp:30: undefined reference to `slClose'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
19 error(s), 0 warning(s) (0 minute(s), 0 second(s))

I am using minGW and have followed all instructions in the tutorial exactly.
What is causing this, and how can I fix it?
I have read the "duplicate question", and it is extremely general, and doesn't help me, as what I'm asking is a question about a very specific instance, and the answers to the other question do not help in this instance.

  • could you try adding an underscore to the imported functions and see if that makes a difference ? that is how the symbols are mangled in the import lib libsigil.dll.a for example : External| _slLoadFont and External| __imp__slLoadFont – Neelabh Mam Sep 14 '20 at 06:27
  • @n-mam I tried it and I got the error `error: '_slWindow' was not declared in this scope` with the note: `note: suggested alternative: 'slWindow'` – DigitalDetective47 Sep 16 '20 at 20:28
  • The import library is for x86 so use x86 build tools. I just tried a simple build inmsvc without including sl.h. Instead, I introduced the below declaration and compiled and linked extern "C" __declspec(dllimport) void slWindow...; cl /c x.cpp link x.obj lib\libsigil.dll.a. It compiled and linked just fine. We could also dynamically link using loadlibrary and getprocaddress on the actual mangled address in the dll. – Neelabh Mam Sep 17 '20 at 04:57
  • @n-mam I'm unclear as to what you're saying here. Also, as stated in the question, I use MinGW, not VSCode. – DigitalDetective47 Sep 17 '20 at 20:26
  • Instead of using sl.h try using this declaration : extern "C" __declspec(dllimport) void slWindow(........); – Neelabh Mam Sep 19 '20 at 03:08
  • `error: expected unqualified-id before string constant` – DigitalDetective47 Sep 19 '20 at 19:22
  • You are obviously doing something wrong. This works perfectly fine both for msvc as well as mingw. Furthermore, I don't see any issues with #include'ing sl.h.. that too complies fine. see my answer below for the link lines. – Neelabh Mam Sep 20 '20 at 04:43

1 Answers1

0

From relative to the sigl extracted zip file use this:

gcc -Wall -g x.cpp -o x.exe -L./lib -lsigil.dll -lstdc++

to compile this:

#include <iostream>
//#include <sl.h>
extern "C" __declspec(dllimport) void slWindow(int width, int height, const char *title, int fullScreen);

int main(void)
{
  slWindow(400, 400, "Simple SIGIL Example", false);
  return 0;
}

and use this:

gcc -Wall -g x.cpp -o x.exe -L./lib -lsigil.dll -lstdc++ -I./include

to compile this:

#include <iostream>
#include <sl.h>
//extern "C" __declspec(dllimport) void slWindow(int width, int height, const char *title, int fullScreen);

int main(void)
{
  slWindow(400, 400, "Simple SIGIL Example", false);
  return 0;
}
Neelabh Mam
  • 300
  • 6
  • 10