Reputation: 343
Im trying to create a library that i could integrate with R in the future, but also use on Command Line
My first step in the path is creating a library, either .a or .so
This is my make file. It compiles fine, but when i look at the folders are empty(Which means i cannot use it in my wilxtest.cpp
EXTERNALLIBS = -lnetcdf_c++ -lgsl -lgslcblas
WILXAPP = src/wilxtest.cpp
CXX = g++
CXXFLAGS = -Wall -ggdb
LIBOBJS: src/wilcoxonParallelTests.o
LIBRARY: lib/WilcoxonParallelTests.a
$(LIBRARY): $(LIBOBJS)
$(CXX) $(CXXFLAGS) ar cr $(LIBRARY) $(LIBOBJS) $(EXTERNALLIBS)
bin/Debug/WilxAstakTest: $(WILXAPP)
$(CXX) $(CXXFLAGS) -o $@ $^ $(EXTERNALLIBS)
Debug: $(LIBRARY) bin/Debug/WilxAstakTest
MkDirs:
mkdir -p obj
mkdir -p lib
mkdir -p bin/Debug
cleanDebug:
rm -rf obj/*
rm -rf lib/*
rm -rf bin/Debug/*
EDITED:
I had ":" instead of "=" after LIBOBJS and LIBRARY. I also didnt have a target to create object file. Here is the updated version:
EXTERNALLIBS = -lnetcdf_c++ -lgsl -lgslcblas
WILXAPP = src/wilxtest.cpp
CXX = g++
CXXFLAGS = -Wall -ggdb
LIBCPP = src/wilcoxonParallelTests.cpp
LIBOBJS = obj/wilcoxonParallelTests.o
LIBRARY = lib/WilcoxonParallelTests.a
$(LIBOBJS): $(LIBCPP)
$(CXX) $(CXXFLAGS) -c $(LIBCPP) -o $(LIBOBJS)
$(LIBRARY): $(LIBOBJS)
ar -cr $(LIBRARY) $(LIBOBJS)
bin/Debug/WilxAstakTest: $(WILXAPP) $(LIBRARY)
$(CXX) $(CXXFLAGS) -o $@ $^ $(EXTERNALLIBS)
Debug: $(LIBRARY) bin/Debug/WilxAstakTest
MkDirs:
mkdir -p obj
mkdir -p lib
mkdir -p bin/Debug
cleanDebug:
rm -rf obj/*
rm -rf lib/*
rm -rf bin/Debug/*
Upvotes: 0
Views: 2774
Reputation: 99094
Instead of this:
$(LIBRARY): $(LIBOBJS)
$(CXX) $(CXXFLAGS) ar cr $(LIBRARY) $(LIBOBJS) $(EXTERNALLIBS)
try this:
$(LIBRARY): $(LIBOBJS)
ar -cr $(LIBRARY) $(LIBOBJS) $(EXTERNALLIBS)
(Further improvements are possible, once the makefile works.)
Upvotes: 2