1 year ago

#354973

test-img

srevrtt

relocation R_X86_64_PC32 against symbol `lua_newstate' can not be used when making a shared object; recompile with -fPIC

I am trying to compile a shared library to ubuntu with Lua, SDL2, SDL2_image, and SDL2_ttf. I get the following compiling error:

relocation R_X86_64_PC32 against symbol `lua_newstate' can not be used when making a shared object; recompile with -fPIC

I know what the compiler is telling me; I just don't know where to put the -fPIC flag. Here is my Makefile:

all: build clean

build:
        g++ -fPIC -c -O3 ./src/*.cpp \
        ./src/libs/window/*.cpp ./src/libs/rectangle/*.cpp ./src/libs/mouse/*.cpp ./src/libs/keyboard/*.cpp ./src/libs/image/*.cpp ./src/libs/font/*.cpp \
        -std=c++17 -g -Wall && g++ -o bin/lgf.so -s -shared -O3 -fPIC *.o -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf -llua -ldl

clean:
        del *.o

.PHONY: build clean

Here is my ".so exporting part" in my main.cpp file if that matters:

extern "C" __attribute__((visibility("default"))) int luaopen_lgf(lua_State *L) {
        luaL_Reg lib[] = {
                {"create", Window::create},
                {"isCloseRequested", Window::isCloseRequested},
                {"sync", Window::sync},
                {"update", Window::update},
                {"setVSync", Window::setVSync},
                {"setIcon", Window::setIcon},
                {"clearScreen", Window::clearScreen},
                {"render", Window::render},
                {"windowChangeColor", Window::changeColorRGB},
                {"close", Window::close},
                {"createRectangle", Rectangle::create},
                {"changeRectangleColor", Rectangle::changeColor},
                {"drawRectangle", Rectangle::draw},

                {"mouseButtonUp", Mouse::mouseButtonUp},
                {"mouseButtonDown", Mouse::mouseButtonDown},
                {"getMouseX", Mouse::getX},
                {"getMouseY", Mouse::getY},

                {"keyup", Keyboard::keyup},
                {"keydown", Keyboard::keydown},

                {"loadImage", ImageLoader::loadImage},
                {"drawImage", ImageLoader::drawImage},

                {"loadFont", FontLoader::loadFont},
                {"loadText", FontLoader::loadText},
                {"renderText", FontLoader::renderText},

                {NULL, NULL}
        };

        luaL_newlib(L, lib);
        return 1;
}

I have tried Googling and I still couldn't find something. I have tried putting the -fPIC flag everywhere, but still no results. I am expecting a .so file inside my ./bin directory.

I am running an Ubuntu-based machine.

c++

ubuntu

lua

sdl-2

.so

0 Answers

Your Answer

Accepted video resources