#Linker errors for sol and lua

1 messages · Page 1 of 1 (latest)

sterile sandal
#

Hello. I'm having issues with properly linking sol and lua in my c++ program. I have the supposedly single header version that requires two other headers (config.hpp) and (forward.hpp). Sol's headers are in the folder structure: "sol/include/sol/".

I have included the folder structure "sol/include/"

I think lua is linked properly because it did work before including sol. Though it might be that sol is expecting lua to be somewhere else.

lua headers are located at "lua/include/"

The error points to a line in sol.hpp

sol\include\sol\sol.hpp undefined reference to `luaL_unref(lua_State*, int, int)'

The line at 10531:

luaL_unref(L_, LUA_REGISTRYINDEX, ref);

Is it possible that I need to include something like -llua in my linker? I'm using Embarcadero Devc++ by the way ,so linker settings use -l.

Help would be greatly appreciated.

night sun
#

Yes you need to link the library

#

Consult the doc for more information

sterile sandal
#

Thanks

sterile sandal
#

Now i'm having trouble with it crashing my program. I narrowed down the issue to the declaration of the lua state.



#ifndef LUA_INTERACT
#define LUA_INTERACT

#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>


class LUAINTERACT
{
    public:
    
    std::string luaFile = "script.lua";
    
    sol::state lua;
    
//    sol::table table;
    
    LUA()
    {
        
//        lua.open_libraries(sol::lib::base,sol::lib::io,sol::lib::math,sol::lib::table);

        // Step 1) Load & Parse File
        
//        try
//        {
//            lua.safe_script_file(luaFile);
//            std::cout << "\nLua File read OK!\n";
//        }
//        catch (const sol::error& e)
//        {
//            std::cout << std::string(e.what()) << "\n";
//            
//        }
        
                
    }
    
    
    

    
    
    
    void update()
    {
        

        
        
        
        
        
        

    }
    
};





#endif

sterile sandal
#

Could somebody please help?

normal phoenix
#
#ifndef LUA_INTERACT
#define LUA_INTERACT

#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>


class LUAINTERACT
{
    public:
    
    std::string luaFile = "script.lua";
    
    sol::state lua;
    
    LUA()
    {
        
                    
    }
    
    void update()
    {
  
    }  
};
#endif
#

After removing all the comments, its just an empty class

#

or almost empty

#

i dont really see any way of this failing

sterile sandal
#

As soon as it starts. Just having the line "sol::state lua;" causes it to crash. I would assume that if it were improperly linked it would not build and compile would it? So I have no idea why it crashes. This is the only instance of sol used in my entire program.Any ideas?

normal phoenix
#

compile your file with -g

#

and then

#

do gdb a.out

#

then run

#

and when it crashes type bt

night sun
normal phoenix
night sun
#

Embarcadero Devc++ has an integrated debugger

normal phoenix
#

thats like using codeblocks

sterile sandal
#

That's personal preference.

sterile sandal
sterile sandal
normal phoenix
night sun
sterile sandal
#

Then please explain it to me cause I don't know what you mean.

night sun
normal phoenix
#

callstack is just list of functions that called the other that called the other ... till the one that had the exception

#

so if function a called b that failed

#

the callstack will be a, b

sterile sandal
#

How do I get a look at the callstack?

normal phoenix
#

or something like that

night sun
#

learn to use your IDE or find a better one

sterile sandal
normal phoenix
#

it has a crapton of features

night sun
sterile sandal
normal phoenix
#

going to visual studio adds like 200features

sterile sandal
sterile sandal
normal phoenix
# sterile sandal Where? I don't see very much documentation on it.
sterile sandal
#

If I need something i''ll use visual studio but for now my current project is in devc++.

normal phoenix
#

you need to google well

normal phoenix
#

but if you dont care, feel free to proceed

sterile sandal
#

Context*

normal phoenix
#

what

sterile sandal
#

I was talking about devc++

normal phoenix
#

im too confused

night sun
sterile sandal
#

Could we not talk about that though? Could you please just kinda help me use gdb? I've not been too sucessful with that in the past.

night sun
normal phoenix
#

yeah

#

exactly

#

i found the same thing lol

normal phoenix
#

wait you dont have separate gcc apart from devc++ do you

sterile sandal
#

Yeah. Could you give me a moment to try it? And then if I have issues could you help me figure them out? I've tried this before and I just need someone to walk me through it.

sterile sandal
#

I have the latest mingw32

normal phoenix
normal phoenix
sterile sandal
#

I don't know. I need to find out.

normal phoenix
#

just go to the directory where your gcc is located then

#

and look for gdb.exe

night sun
#

@sterile sandal I don't recommend you try and go this way, ideally you figure out how to do it from your IDE (the link above should help you get started) or you pick a better IDE

sterile sandal
#

The version info file for my compiler says the following:

This is the winlibs Intel/AMD 32-bit standalone build of:
- GCC 13.1.0
- GDB 13.2
- MinGW-w64 11.0.0 (linked with msvcrt)
- GNU Binutils 2.40
- GNU Make 4.4.1
- PExports 0.47
- dos2unix 7.5.0
- Yasm 1.3.0
- NASM 2.16.01
- JWasm 2.12pre
- ccache version 4.8.1
- CMake 3.26.4
- ninja 1.11.1
- doxygen 1.9.7

So It looks like it includes gdb.

sterile sandal
normal phoenix
#

alright, open cmd and check if its in your path

night sun
normal phoenix
#

by doing just

#

gdb.exe

#

what does it say

sterile sandal
#

It's there

normal phoenix
#

alright

#

so now, you can compile your program with the -g flag

#

just cd into the directory where your program is

sterile sandal
#

Yes.

normal phoenix
#

and do g++ -g program.cpp

#

or something in that sence

sterile sandal
#

Ok. The first error it output is this:

C:/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/bin/ld.exe: Desk Engine.exe:crtexe.c:(.text+0xba): multiple definition of `WinMainCRTStartup'; C:/mingw32/bin/../lib/gcc/i686-w64-mingw32/13.1.0/../../../../i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0xba): first defined here

normal phoenix
#

I have no idea how winapi works

#

it almost seems like it has just included stdlib twice

#

maybe with -nostdlib?

sterile sandal
#

Could it be that the c part of my compiler is linked incorrectly?

sterile sandal
#

I wonder if its a namespace issue. Like if sol or lua is having a conflicting namespace with win32.

normal phoenix
sterile sandal
#

Seems to be the typical out-of-bounds error, though I don't know if that's only for out of bounds.

"Process exited after 0.03199 seconds with return value 3221225781"

normal phoenix
#

first google result might work

normal phoenix
#

its just windows errors like 0xc0000001

#

look

#

hex is really useful for stuff

sterile sandal
sterile sandal
normal phoenix
#

the first result

#

after googling

#

multiple definition of WinMainCRTStartup

#

you just have to select the proper parts and it finds it all instantly

night sun
#

@sterile sandal see? Jonas isn't trying to work with your setup

normal phoenix
sterile sandal
normal phoenix
#

vs is great

#

other than being single platform and 60gigs

#

its great

sterile sandal
normal phoenix
night sun
sterile sandal
#

Every time I use a video editor it temporarily takes up 40 GB and if I have visual studio that leaves me with no more space to work on videos.

normal phoenix
#

emptying trashbin also works very often

normal phoenix
#

if its visual studio it can be a hard drive thats about to break anyway

sterile sandal
normal phoenix
#

on normal laptops back in the day you could upgrade everything

sterile sandal
#

Yeah. A modern one. But it can change the drive. I just can't add a secondary drive.

sterile sandal
#

yep

normal phoenix
#

but anyways

#

hmmm

#

cant you just uninstall some game or something

sterile sandal
#

I don't even have games. I'm literally just overbogged down by software that I use all the time.

normal phoenix
#

also, if your video editor takes 40gigs and youre not editing 2hour 4k things

#

your vid editor is screwed up so bad

sterile sandal
#

I guess my reason for using devc++ is that it's simple ,fast,and lightweight. Perhaps I just prefer that over complicated,slower,and heavyweight.

#

Even if I lose certain features.

normal phoenix
#

Windows is overall painful for c++, and vs is what makes it less painful

sterile sandal
#

But anyways, thanks for all of your help. This gives me some direction to research into. I'm grateful.

sterile sandal