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 8963851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:27:01+00:00 2026-06-15T16:27:01+00:00

Some context: I’m trying to build the Lua source into a DLL (learning purposes!),

  • 0

Some context: I’m trying to build the Lua source into a DLL (learning purposes!), on Windows with Pelles C (using C). Targeting x64 mainly, if that is significant.

By using the DLL wizard in my Pelles C, it autogenerates a DLLMain.c with a sample function and DLLMain.h. This is fine, except now I’m not sure how to export all the other lua functions as well. Simply adding all the source files (which is too simple to possibly ever work, but you never know…) that the Lua website tells me to and then building it with appropriate #defines just exports the sample function, which I’ve checked using polib.exe:

Polib results

Some source:

Auto-generated DLL main:

/****************************************************************************
 *                                                                          *
 * File    : dllmain.c                                                      *
 *                                                                          *
 * Purpose : Generic Win32 Dynamic Link Library (DLL).                      *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/00  Created                                              *
 *                                                                          *
 ****************************************************************************/

#define WIN32_LEAN_AND_MEAN  /* speed up */
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>

/*
 * Include our "interface" file and define a symbol
 * to indicate that we are *building* the DLL.
 */
#define _LUADLLTE_
#include "LUADLLTE.h"
                            //!!!~~~!!!~~~!!!~~~!!!~~~!!!~~~!!!~~~!!!~~~!!!
#include "lua.h"            //I added these 3. Do these not go here?
#include "lauxlib.h"        //They are the 3 headers that every Lua tutorial
#include "lualib.h"         //includes.
                            //~~~!!!~~~!!!~~~!!!~~~!!!~~~!!!~~~!!!~~~!!!~~~

/****************************************************************************
 *                                                                          *
 * Function: DllMain                                                        *
 *                                                                          *
 * Purpose : DLL entry and exit procedure.                                  *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/00  Created                                              *
 *                                                                          *
 ****************************************************************************/

BOOL APIENTRY DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            /*
             * Microsoft says:
             *
             * blah comments blah
             */
            break;

        case DLL_THREAD_ATTACH:
            /*
             * Microsoft says:
             *
             * blah blah
             */
            break;

        case DLL_THREAD_DETACH:
            /*
             * blah blah
             */
            break;

        case DLL_PROCESS_DETACH:
            /*
             * blah
             */
            break;
    }

    /* Return success */
    return TRUE;
}

/****************************************************************************
 *                                                                          *
 * Function: SampleFunction                                                 *
 *                                                                          *
 * Purpose : Sample function which does nothing useful.                     *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/00  Created                                              *
 *                                                                          *
 ****************************************************************************/

LUADLLTEAPI int WINAPI SampleFunction(int a, int b)
{
    /* TODO: Replace with your own code */
    return a * b;
}

Aut-generated header:

// INCLUDE FILE generated by "Pelles C for Windows, version 3.00".

#ifndef _LUADLLTE_H
#define _LUADLLTE_H

#ifdef _LUADLLTE_
#define LUADLLTEAPI  __declspec(dllexport)
                           //!!!~~~!!!~~~!!!~~~!!!~~~!!!~~~!!!~~~!!!~~~!!!
#define LUA_BUILD_AS_DLL   //I added these 3 defines as well.
#define LUA_CORE           //See next source excerpt for the 
#define LUA_LIB            //reasoning.
                           //!!!~~~!!!~~~!!!~~~!!!~~~!!!~~~!!!~~~!!!~~~!!!
#else
#define LUADLLTEAPI  __declspec(dllimport)
#endif /* _LUADLLTE_ */

#ifndef WINAPI
#define WINAPI  __stdcall
#endif

LUADLLTEAPI int WINAPI SampleFunction(int, int);

#endif /* _LUADLLTE_H */

luaconf.h, relevant (i think?) portion:

/*
@@ LUA_API is a mark for all core API functions.
@@ LUALIB_API is a mark for all auxiliary library functions.
@@ LUAMOD_API is a mark for all standard library opening functions.
** CHANGE them if you need to define those functions in some special way.
** For instance, if you want to create one Windows DLL with the core and
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
*/
#if defined(LUA_BUILD_AS_DLL)   /* { */

#if defined(LUA_CORE) || defined(LUA_LIB)   /* { */
#define LUA_API __declspec(dllexport)
#else                       /* }{ */
#define LUA_API __declspec(dllimport)
#endif                      /* } */

#else               /* }{ */

#define LUA_API     extern

#endif              /* } */


/* more often than not the libs go together with the core */
#define LUALIB_API  LUA_API
#define LUAMOD_API  LUALIB_API

These defines determine how the lua api calls get built, depending on what symbols are defined. That’s why I added them in the header file.

I can add functions to the autogenerated header/c file and they will show up in the lib according to polib.exe. This leads me to think that I need to go and find every single function call and move it to the dllmain file, but that doesn’t sound like the optimal way to do this.

These sources didn’t really answer this question:

How do you merge multiple static linked libraries into a single dll given each static lib defines exported functionality (vc++ 2008)?

would appreciate for some one pointing me to good DLL tutorial

~All the tutorials I have found are single-file DLL tutorials.

Compiling & Decompiling dll files

~This one came close, but no answer along the lines I need.

~The Lua website and build documentation aren’t very clear/specific when it comes to Windows.

It’s entirely possible I’m missing something pretty obvious. I went through single source/single header file DLL’s first to get a feel for it, and now I want to try compiling Lua (which i actually want to try to learn about at some point). Let me know if this question is a little convoluted. I figure it is a problem with my DLL knowledge, not with Lua, so my question is:

How do you build a DLL file containing multiple source files, with functions to be exported in multiple files?

PS: What fundamental know-how am I missing regarding this topic, if that may be the root cause? Also, sorry for the length….just noticed…

Edit: Solved! Thank you Mud.

Method: In Pelles C, go to Project Options… -> Compiler tab, and enter LUA_BUILD_AS_DLL LUA_LIB (or LUA_BUILD_AS_DLL LUA_CORE or LUA_BUILD_AS_DLL LUA_CORE LUA_LIB)under the Define preprocessor symbols line.

Polib fixed

  • 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-06-15T16:27:03+00:00Added an answer on June 15, 2026 at 4:27 pm

    All the Lua API functions which you want exported are prefixed with LUA_API. As you noted, to define LUA_API correctly (for Visual Studio, GCC, et al.) you need only define LUA_BUILD_AS_DLL and LUA_LIB.

    However, you define them in a header file, so those definitions only exist in the files that include that header — i.e. none of the Lua files include your header.

    You need to define those symbols in your project-settings/makefile/whatever so they are defined during compilation of the Lua sources.

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

Sidebar

Related Questions

For some context, I'm trying to build and use the LiME forensics tool .
Some context for this code, what I am trying to do is create a
First, some context: I'm a Python developer who has written a medium-sized application using
I am trying to read file and split its line to get some context(Computer
Context I'm trying to have some "plugins" (I'm not sure this is the correct
Some context here...I have a System.Windows.Window that is used to display a modal message
To put the question into some context, the system exposing the web service uses
First some context. I've been using nonce tokens to sign my form data in
To set some context, I'm in the process of learning Clojure, and Lisp development
Some context: I'm trying to highlight all occurrences of some searched text in 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.