C compilation error, external library functions not found

I'm trying to compile a project (which is written on a 32bit OS, Ubuntu). I'm using the given makefiles and I installed all the necessary external libraries (on a 64bit Ubuntu).

I don't get a library linking error but the functions implemented in SDL and argtable2 (external libraries) are not recognized. I only changed the path to the libSDL_gfx.so so that it points to the 64bit installation.

How can i solve this compilation issue?

Code:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <argtable2.h>

#include "../../problems/generative_model.h"
#include "../../problems/viewer.h"
#include "opcas.h"


int main(int argc, char* argv[]) {

    double discountFactor;
    unsigned int maxNbEvaluations;
    char isTerminal = 0;
    char isDisplayed = 1;
    char verbose = 0;
    unsigned int nbTimestep = 0;
    double L;

    opcas_instance* instance = NULL;

    state* crtState = NULL;
    state* nextState = NULL;
    double reward = 0.0;
    double* optimalAction = NULL;

    struct arg_dbl* g = arg_dbl1("g", "discountFactor", "<d>", "The discount factor for the problem");
...
    return EXIT_SUCCESS;
}

The makefile looks like:

CC := gcc
FLAGS := -W -Wall -g -ansi -std=c99 -pedantic
LIBS := -lm -lSDL -lSDLmain /usr/lib/x86_64-linux-gnu/libSDL_gfx.so -largtable2
BIN_DIR := bin
OBJ_DIR := obj

all: $(BIN_DIR)/opcas_ball $(BIN_DIR)/opcas_inverted_pendulum 
$(BIN_DIR)/opcas_mountain_car $(BIN_DIR)/opcas_acrobot $(BIN_DIR)/opcas_spring_pendulum

$(BIN_DIR)/opcas_ball: $(OBJ_DIR)/opcas_1.o $(OBJ_DIR)/main_opcas_1.o $(OBJ_DIR)/ball.o $(OBJ_DIR)/viewer_ball.o $(OBJ_DIR)/opcas_drawing_procedure_ball.o $(OBJ_DIR)/svgFile.o
    $(CC) $(FLAGS) $(LIBS) $^ -o $@

The error is (similar error for SDL functions):

gcc -W -Wall -g -ansi -std=c99 -pedantic -lm -lSDL -lSDLmain /usr/lib/x86_64-linux-

gnu/libSDL_gfx.so -largtable2 obj/opcas_1.o obj/main_opcas_1.o obj/ball.o 

obj/viewer_ball.o obj/opcas_drawing_procedure_ball.o obj/svgFile.o -o bin/opcas_ball
obj/main_opcas_1.o: In function `main':
/home/elod/UTwork/RealTime_Cpp/continuous_action_space/algorithms/opcas/main_opcas.c:63: undefined reference to `arg_dbl1'

Answers


Options specifying libraries need to go into the command-line after the object using symbols out of the libraries given.

So this command:

 gcc -W -Wall -g -ansi -std=c99 -pedantic -lm -lSDL -lSDLmain /usr/lib/x86_64-linux-gnu/libSDL_gfx.so -largtable2 obj/opcas_1.o obj/main_opcas_1.o obj/ball.o obj/viewer_ball.o obj/opcas_drawing_procedure_ball.o obj/svgFile.o -o bin/opcas_ball

should look like this

 gcc -W -Wall -g -ansi -std=c99 -pedantic /usr/lib/x86_64-linux-gnu/libSDL_gfx.so  obj/opcas_1.o obj/main_opcas_1.o obj/ball.o obj/viewer_ball.o obj/opcas_drawing_procedure_ball.o obj/svgFile.o -o bin/opcas_ball -lm -lSDL -lSDLmain -largtable2

As a rule of thumb, which would work in nearly all cases: Place -lxyz options at the end of the link command.


If you have the source files, compile it in 64 platform and make .so and then link. Else compile with -m32. It will work


Need Your Help

Client SSL with an Intermediate Certificate

ssl nginx

I have a self-signed root certificate and an intermediate certificated signed by that root. Basically something like this:

PHP shows up blank inf IE & Firefox but not Safari

php internet-explorer firefox

I am new to php &amp; have a simple "tell a friend" code. A popup is suppose to come up &amp; show that the message has been sent to the friend. This works great in Safari, however it shows up blan...