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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:44:30+00:00 2026-06-11T05:44:30+00:00

I am attempting to embed lua code in C++, and I’m getting a strange

  • 0

I am attempting to embed lua code in C++, and I’m getting a strange compiler error. Here’s my code:

#include <stdio.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}

int main() {
    lua_State *luaVM = luaL_newstate();
    if (luaVM == NULL) {
        printf("Error initializing lua!\n");
        return -1;
    }

    luaL_openlibs(luaVM);

    luaL_dofile(luaVM, "test.lua");

    lua_close(luaVM);

    return 0;
}

compiled with:

g++ -Wall -o embed -llua embed.cpp

and the error is:

g++ -Wall -o embed -llua embed.cpp
/tmp/ccMGuzal.o: In function `main':
embed.cpp:(.text+0x47): undefined reference to `luaL_loadfilex'
embed.cpp:(.text+0x72): undefined reference to `lua_pcallk'
collect2: error: ld returned 1 exit status

I am not calling luaL_loadfilex or lua_pcallk from my code, which lends itself to the assumption that the problem is not in my code, but in lua itself. does anyone have any ideas here?

UPDATE

Here is my version info:

$ lua -v
Lua 5.2.0  Copyright (C) 1994-2011 Lua.org, PUC-Rio
  • 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-11T05:44:32+00:00Added an answer on June 11, 2026 at 5:44 am

    Ultimately the problem was that the libraries are named differently by version. When installed from the repository, the libraries are called liblua5.x and liblualib5.x, and therefore the following command was required:

    g++ -Wall -o embed embed.cpp -llua5.2 -llualib5.2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Attempting to build an interface and generics based graph and getting an odd error
I'm attempting to place some embed code into a Premium WordPress Theme. NOTE: I'm
I am attempting to follow the besic guide given here on embedding lua into
Attempting to parse json from a url requiring login. Including all my code here
I am attempting to use GoogleDocs Viewer to embed a PDF on my webpage.
I'm attempting to embed the very convenient Google Translate translate element into a webpage,
Attempting to compile the following code under Qt SDK 4.7.4 for Desktop - MinGW
Attempting to follow the directions as specified on http://code.google.com/p/gears/wiki/BuildingGearsForWindows my attempts are failing at
I'm attempting to embed an HTML5 audio element pointing to MP3 or OGG data
I'm attempting to scrape a website and I need to get at an embed

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.