0

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/*
user1047833
  • 343
  • 2
  • 7
  • 17

1 Answers1

2

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.)

Beta
  • 96,650
  • 16
  • 149
  • 150
  • Hey. I made you changes and a few other changes and i got it to create obj and .a files. However, now the wilxtest cannot find wilcoxonParallelTests.h . I edited the description above to give you more precise information of what i have. Also, what did you mention about improving Makefile? – user1047833 Aug 05 '13 at 04:41
  • Where is `wilcoxonParallelTests.h`? If it's in, say, `headers/`, then you should add `-Iheaders` to the command in question. Also, if you're *not* having this problem with `wilcoxonParallelTests`, that suggests that something is fishy elsewhere (but there are several things it could be). – Beta Aug 05 '13 at 17:21
  • Hey thanks! Isrc did it. im having source and header files in the same folder. Any tips on how to improve the overall quality of the header file? – user1047833 Aug 05 '13 at 19:54
  • @user1047833: The header file? I'd have to see it. As for the makefile, I'd suggest using [automatic variables](http://www.gnu.org/software/make/manual/make.html#Automatic-Variables) and making the `$(LIBOBJS)` rule a [static pattern rule](http://www.gnu.org/software/make/manual/make.html#Static-Pattern). – Beta Aug 05 '13 at 20:05
  • I meant the make file :) Thanks for the links! – user1047833 Aug 06 '13 at 05:03