Question

I would like to be able to compile a c++ source file without using a makefile. And here is a prototype of my problem... I have the following .cpp file

// special libraries to include
#include "acado.h"  
#include "auxiliary_functions.c" 
/* -------------------------- */
// Create objects for special classes 
   ACADOvariables acadoVariables; 
   ACADOworkspace acadoWorkspace;

int main(){
    // perform task A_1
    // perform task A_2 
    // Tasks A_1 and A_2 depend on the specially included headers
    return 0;
}

and in the same directory I have the following makefile that allows me to compile the .cpp file successfully

LDLIBS = -lm 
CXXFLAGS = -O3 -finline-functions -I. -I./qpoases/INCLUDE -I./qpoases/SRC
CFLAGS = -O3
CC     = g++

OBJECTS = \
    ./qpoases/SRC/QProblemB.o       \
    ./qpoases/SRC/Bounds.o          \
    ./qpoases/SRC/Constraints.o     \
    ./qpoases/SRC/SubjectTo.o       \
    ./qpoases/SRC/Indexlist.o       \
    ./qpoases/SRC/CyclingManager.o  \
    ./qpoases/SRC/Utils.o           \
    ./qpoases/SRC/MessageHandling.o \
    ./qpoases/solver.o              \
    integrator.o                    \
    condensing.o                    \
    gauss_newton_method.o 

.PHONY: all
all: test libacado_exported_rti.a

test: ${OBJECTS} test.o

./qpoases/solver.o    : ./qpoases/solver.hpp
integrator.o          : acado.h
condensing.o          : acado.h
gauss_newton_method.o : acado.h   ./qpoases/solver.hpp
test.o                : acado.h   ./qpoases/solver.hpp

libacado_exported_rti.a: ${OBJECTS}
    ar r $@ $?

${OBJECTS} : ./qpoases/solver.hpp

.PHONY : clean
clean :
    -rm -f *.o *.a ./qpoases/SRC/*.o ./qpoases/SRC/*.a test

Now, for my purposes, I would like to delete this makefile from the .cpp file directory. At the same time, I would like to be able to compile the .cpp file ...

Knowing that the object files and libraries that the makefile refers to will be at their respective directories ....

So, everything I would like to do, is to compile the .cpp file without having a makefile.

Is it possible to do something like this for the given case ? ... If yes, your suggestions are really appreciated !

Was it helpful?

Solution

Assuming that your main() function is in the test.cpp, and you want the executable named "test" you can invoke the compiler directly from the directory where you would invoke make:

 g++ test.cpp -O3 -finline-functions -I. -I./qpoases/INCLUDE -I./qpoases/SRC -lm -o test ./qpoases/SRC/QProblemB.o ./qpoases/SRC/Bounds.o ./qpoases/SRC/Constraints.o ./qpoases/SRC/SubjectTo.o ./qpoases/SRC/Indexlist.o ./qpoases/SRC/CyclingManager.o ./qpoases/SRC/Utils.o ./qpoases/SRC/MessageHandling.o ./qpoases/solver.o integrator.o condensing.o gauss_newton_method.o
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top