Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6924377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:39:20+00:00 2026-05-27T10:39:20+00:00

This is a really specific compilation problem involving C++, SWIG and Lua. I have

  • 0

This is a really specific compilation problem involving C++, SWIG and Lua.

I have a really simple base code :

[AClass.hpp]

class AClass {
public:
    AClass();
};

[AClass.cpp]

#include "AClass.hpp"

AClass::AClass() {}

[main.cpp]

#include "AClass.hpp"

int main() {
    AClass my_a;
}

At this point, there is no matter with compilation.
I first compile the class in libengine.dll and then use the shared library to build the executable.

Let’s introduce a SWIG module, and add it to the dll :

[AClass.i]

%module M_AClass

%{
#include "AClass.hpp"
%}

%include "AClass.hpp"

Henceforth, when linking everything in an executable, I got the following error :

g++ -c main.cpp
g++ -c AClass.cpp
swig.exe -c++ -lua AClass.i
g++ -Iinclude -c AClass_wrap.cxx
g++ AClass.o AClass_wrap.o -shared -o libengine.dll -Wl,--out-implib,libengine.dll.a -L. -llua5.1
Creating library file: libengine.dll.a
g++ main.o libengine.dll.a -o main.exe
main.o:main.cpp:(.text+0x16): undefined reference to `AClass::AClass()'
collect2: ld returned 1 exit status

Would anyone have a clue ? I tried looking into the dll with nm but I can’t figure how adding another .o to the shared library can “hide” a method (this isn’t specific to constructors).


To reproduce the context, here are the necessary files to put in a directory to build the test :

include/ # Contains "lauxlib.h", "lua.h" & "luaconf.h"
liblua5.1.dll
AClass.hpp
AClass.cpp
AClass.i
main.cpp
Makefile

And finally, here is the Makefile content :

ifneq (,$(findstring Linux,$(shell uname -o)))
    EXEC := main
    LIB := libengine.so
    LIB_FLAGS := -o $(LIB)
else
    EXEC := main.exe
    LIB := libengine.dll.a
    LIB_FLAGS := -o libengine.dll -Wl,--out-implib,$(LIB)
    #NO DIFFERENCE using ".dll.a" as in CMake (option: -Wl,--out-implib,) or only ".dll"

    ifdef SystemRoot
    # Pure Windows, no Cygwin
        RM := del /Q
    endif
endif

LANG_LIB := -L. -llua5.1
LANG_INC := include
LANG_SWIG := -lua

all: clean $(EXEC)

clean:
    $(RM) main *.exe *_wrap.cxx *.o libengine.*

$(EXEC): main.o $(LIB)
    g++ $^ -o $@

main.o: main.cpp
    g++ -c $<

#NO PB without dependency to AClass_wrap.o
$(LIB): AClass.o AClass_wrap.o
    g++ $^ -shared $(LANG_LIB) $(LIB_FLAGS)

AClass.o: AClass.cpp
    g++ -fPIC -c $<

AClass_wrap.o: AClass_wrap.cxx
    g++ -fPIC -I$(LANG_INC) -c $<

AClass_wrap.cxx: AClass.i
    swig -c++ $(LANG_SWIG) $<

This was tested under Windows Seven, with MingGW g++ v4.5.2, SWIG 2.0.2 and Lua5.1.

EDIT: The problem also appear when SWIG-exporting to tcl. However, there is absolutely no problem compiling under Linux. I compared the generated AClass_wrap.cxx, they are similar.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:39:21+00:00Added an answer on May 27, 2026 at 10:39 am

    g++ under mingw might require __declspec(dllimport/export)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this really simple piece of code that I thought was the correct
This is a question not really about programming (is not specific to any language
This really has my stumped today. I'm sure its simple, but... Here is my
I'm using visual studio to program this small TcpServer. It's really specific. The server
I have a webpage where Firefox 2 displays the font certain, really specific elements,
Currently, I have 36 variables that are being shuffled (for a really specific WP
I have seen several similar questions to this, but none that addresses my specific
This question might be a bit sketchy because I do not have the code
This is not really language-specific, but I'll use Python to explain my question. My
This isn't really S3-specific, it's more just a basic JavaScript question. Is there a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.