I am trying to use clang as a library, but I am not sure how to link the files in the Makefile.
Trying out the ASTVisitor code from: https://clang.llvm.org/docs/RAVFrontendAction.html
Here is my Makefile for reference:
CC=g++
Includes= /usr/lib/llvm-6.0/include/
Libs= /usr/lib/llvm-6.0/lib/
CLANGLIBS=-lclangTooling -lclangFrontendTool -lclangFrontend -lclangDriver -lclangSerialization -lclangCodeGen -lclangParse -lclangSema -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangAnalysis -lclangARCMigrate -lclangRewrite -lclangRewriteFrontend -lclangEdit -lclangAST -lclangLex -lclangBasic -lclang
run:
LD_PRELOAD=../../llvm-project/build/lib/libclang.so ./clang_parser.out
all: clang_parser.cpp
$(CC) -I$(Includes) -L$(Libs) clang_parser.cpp -o a.out $(CLANGLIBS)
clean:
rm clang_parser.out
I have installed clang as a library i.e. done sudo apt-get install libclang-dev
I get the following error:
clang_parser.cpp:13:10: fatal error: clang/Frontend/FrontendActions.h: No such file or directory
#include <clang/Frontend/FrontendActions.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:10: recipe for target 'all' failed
make: *** [all] Error 1
Any best practices on using apt installed packages in C/C++ projects are appreciated too.
Installed a number of packages just to make sure:
sudo apt-get install libclang-dev llvm clang clang-tools
This is the compilation command for reference (it includes all libraries which may be used):
clang++ `llvm-config --cxxflags --ldflags` clang_parser.cpp $(CLANGLIBS2) `llvm-config --libs --system-libs` -g -o tool
where
CLANGLIBS2=-lclangTooling -lclangFrontendTool -lclangFrontend -lclangDriver -lclangSerialization -lclangCodeGen -lclangParse -lclangSema -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangAnalysis -lclangARCMigrate -lclangRewrite -lclangRewriteFrontend -lclangEdit -lclangAST -lclangASTMatchers -lclangLex -lclangBasic -lclang
Set up all .so, .a files in /usr/lib/llvm-6.0/lib as LD_LIBRARY_PATH by doing:
export LD_LIBRARY_PATH=/usr/lib/llvm-6.0/lib
ldconfig
Having gone through the process myself of creating a program that uses
Clang as a library, I thought I'd post my own working Makefile.
Key elements:
It uses a binary distribution downloaded from
https://releases.llvm.org/download.html rather than
installing through apt-get so I can control exactly
what version is in use.
Like the OP, I'm using (GNU) make rather than cmake
to minimize the mystery of what is happening.
It uses the llvm-config program to get most of the required
compile and link options. Specifically, llvm-config --cxxflags
gets the preprocessor and compilation options, and
llvm-config --ldflags --libs --system-libs gets the linker options.
I'm using the same hardcoded list of clang libraries as the OP.
I do not know a way to obtain this list other than by studying what
cmake does in an llvm source tree build. There is not anything
like clang-config to help.
The llvm libraries must come after the clang libraries.
(This is obvious in retrospect, but I wasted a fair bit of time since
the linker error messages are not easy to diagnose when dealing with
literally hundreds of unfamiliar libraries.)
For completeness, I'm using GCC-9.3.0 on Linux Mint 20.1, x86_64.
My Makefile:
# clang-as-lib/Makefile
# Attempt to compile and link with clang as a library.
# Originally based on:
# https://stackoverflow.com/questions/59888374/using-clang-as-a-library-in-c-project
# Default target.
all:
.PHONY: all
# ---- Paths ----
# Installation directory from a binary distribution.
# Has five subdirectories: bin include lib libexec share.
# Downloaded from: https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz
CLANG_LLVM_INSTALL_DIR = $(HOME)/opt/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04
# Program to query the various LLVM configuration options.
LLVM_CONFIG = $(CLANG_LLVM_INSTALL_DIR)/bin/llvm-config
# ---- Compiler options ----
# C++ compiler.
CXX = g++
# Compiler options, including preprocessor options.
CXXFLAGS =
# Without optimization, adding -g increases compile time by ~20%.
#CXXFLAGS += -g
# Without -g, this increases compile time by ~10%. With -g -O2, the
# increase is ~50% over not having either.
#CXXFLAGS += -O2
CXXFLAGS += -Wall
# Silence a warning about a multi-line comment in DeclOpenMP.h.
CXXFLAGS += -Wno-comment
# Get llvm compilation flags.
CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags)
# Linker options.
LDFLAGS =
# Set of clang libraries to link with.
LDFLAGS += -lclangTooling
LDFLAGS += -lclangFrontendTool
LDFLAGS += -lclangFrontend
LDFLAGS += -lclangDriver
LDFLAGS += -lclangSerialization
LDFLAGS += -lclangCodeGen
LDFLAGS += -lclangParse
LDFLAGS += -lclangSema
LDFLAGS += -lclangStaticAnalyzerFrontend
LDFLAGS += -lclangStaticAnalyzerCheckers
LDFLAGS += -lclangStaticAnalyzerCore
LDFLAGS += -lclangAnalysis
LDFLAGS += -lclangARCMigrate
LDFLAGS += -lclangRewrite
LDFLAGS += -lclangRewriteFrontend
LDFLAGS += -lclangEdit
LDFLAGS += -lclangAST
LDFLAGS += -lclangLex
LDFLAGS += -lclangBasic
LDFLAGS += -lclang
# *After* clang libs, the llvm libs.
LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags --libs --system-libs)
# ---- Recipes ----
# Compile a C++ source file.
%.o: %.cpp
$(CXX) -c -o $# $(CXXFLAGS) $<
# Executable.
all: FindClassDecls.exe
FindClassDecls.exe: FindClassDecls.o
$(CXX) -g -Wall -o $# $^ $(LDFLAGS)
# Run it.
.PHONY: run
run: FindClassDecls.exe
./FindClassDecls.exe "namespace n { namespace m { class C {}; } }"
.PHONY: clean
clean:
$(RM) *.o *.exe
# EOF
FindClassDecls.cpp (from RAVFrontendAction.html):
// FindClassDecls.cpp
// https://clang.llvm.org/docs/RAVFrontendAction.html
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Tooling/Tooling.h"
using namespace clang;
class FindNamedClassVisitor
: public RecursiveASTVisitor<FindNamedClassVisitor> {
public:
explicit FindNamedClassVisitor(ASTContext *Context)
: Context(Context) {}
bool VisitCXXRecordDecl(CXXRecordDecl *Declaration) {
if (Declaration->getQualifiedNameAsString() == "n::m::C") {
FullSourceLoc FullLocation = Context->getFullLoc(Declaration->getBeginLoc());
if (FullLocation.isValid())
llvm::outs() << "Found declaration at "
<< FullLocation.getSpellingLineNumber() << ":"
<< FullLocation.getSpellingColumnNumber() << "\n";
}
return true;
}
private:
ASTContext *Context;
};
class FindNamedClassConsumer : public clang::ASTConsumer {
public:
explicit FindNamedClassConsumer(ASTContext *Context)
: Visitor(Context) {}
virtual void HandleTranslationUnit(clang::ASTContext &Context) {
Visitor.TraverseDecl(Context.getTranslationUnitDecl());
}
private:
FindNamedClassVisitor Visitor;
};
class FindNamedClassAction : public clang::ASTFrontendAction {
public:
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
clang::CompilerInstance &Compiler, llvm::StringRef InFile)
{
return std::make_unique<FindNamedClassConsumer>(&Compiler.getASTContext());
}
};
int main(int argc, char **argv) {
if (argc > 1) {
clang::tooling::runToolOnCode(std::make_unique<FindNamedClassAction>(), argv[1]);
}
}
// EOF
Related
So I am using nvidia's deepstream sdk and trying to modify the makefile of one of the sample examples given as I wish to link and add my own libraries. This is the makefile being employed where I am setting the path of the CUSTOM_LIB to point to the location of my library. The issue is the project gets compiled successfully but during run time, its unable to find the custom library. I performed ldd on the executable generated and there also it was showing the library as 'not found'. I think it's something to do with rpath but I am not sure about that.
APP:= sample
TARGET_DEVICE = $(shell gcc -dumpmachine | cut -f1 -d -)
NVDS_VERSION:=4.0
LIB_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/lib/
ifeq ($(TARGET_DEVICE),aarch64)
CFLAGS:= -DPLATFORM_TEGRA
endif
CUDA_VER:=10.0
CC:=g++
SRCS:= $(wildcard ../src/*.c)
#SRCS+= $(wildcard ../../apps-common/src/*.c)
#SRCS+=
INCS:= $(wildcard ../include/*.h)
PKGS:= gstreamer-1.0 gstreamer-video-1.0 x11 opencv
OBJS:= $(SRCS:.c=.o)
CFLAGS+= -I../include -I/usr/include -I$(CUSTOM_LIB)/include -I/usr/local/cuda-10.0/targets/aarch64-linux/include/ -I/usr/include/jsoncpp -DDS_VERSION_MINOR=0 -DDS_VERSION_MAJOR=4 -fpermissive -Wnarrowing
LIBS+= -L$(LIB_INSTALL_DIR) -L/usr/lib/aarch64-linux-gnu -L$(CUSTOM_LIB)/lib -L/usr/lib/aarch64-linux-gnu/ -lcurl -letlic -letolm -lssl -lcrypto -llogger -lpthread -lsqlite3 -ljsoncpp -lnvdsgst_meta -lnvbufsurface -lnvbufsurftransform -lnvds_meta -lnvdsgst_helper -lnvds_utils -lm -L/usr/local/cuda-$(CUDA_VER)/lib64/ -lcudart \
-lgstrtspserver-1.0 -Wl,-rpath,$(LIB_INSTALL_DIR)
CFLAGS+= `pkg-config --cflags $(PKGS)`
LIBS+= `pkg-config --libs $(PKGS)`
all: $(APP)
debug: CXXFLAGS += -DDEBUG -g
debug: CFLAGS += -DDEBUG -g
debug: $(APP)
%.o: %.c $(INCS) Makefile
$(CC) -c -o $# $(CFLAGS) $<
$(APP): $(OBJS) Makefile
$(CC) -o $(APP) $(OBJS) $(LIBS)
clean:
rm -rf $(OBJS) $(APP)
You need to set rpath to a colon-separated list of directories where your libraries are found. You only add LIB_INSTALL_DIR but not CUSTOM_LIB_DIR. Generally everything you pass to -L you need to pass to -rpath too, unless there is a specific reason not to. For example, if you are building a package that has more than a single library and you are going to install in a standard place like /usr/lib, you don't have to add the directory where libraries temporarily live to -rpath. If you are going to install to a non-standard directory, add that directory.
I'm doing some modifications to an existing project which is pretty big, so it's built with the autotools. The modifications involve the Ibex library, so I've added an #include "ibex.h" in one of the source files. The library is properly installed on my system, I have the following files:
/usr/local/lib/libibex.a
/usr/local/include/ibex/ibex.h
/usr/local/share/pkgconfig/ibex.pc
Results of the pkg-config commands:
$ pkg-config --libs ibex
-L/usr/local/lib -libex -lprim -lClp -lCoinUtils -lm
$ pkg-config --cflags ibex
-frounding-math -ffloat-store -I/usr/local/include -I/usr/local/include/ibex
The original Makefile.am corresponding to the compil unit I want to get to use ibex, is as follows:
noinst_LTLIBRARIES = liblrasolver.la
AM_CPPFLAGS=$(config_includedirs)
liblrasolver_la_SOURCES = LAVar.h LAVar.C Delta.h Delta.C LRASolver.h LRASolver.C LAArray.h LAArray.C LARow.h LARow.C LAColumn.h LAColumn.C
if WANT_LIBRARY
include_HEADERS = Delta.h LAArray.h LAColumn.h LARow.h LAVar.h LRASolver.h
endif
I modified it this way:
noinst_LTLIBRARIES = liblrasolver.la
AM_CPPFLAGS=$(config_includedirs) `pkg-config --cflags ibex`
AM_LDFLAGS=`pkg-config --libs ibex` -lblas -llapack
liblrasolver_la_SOURCES = LAVar.h LAVar.C Delta.h Delta.C LRASolver.h LRASolver.C LAArray.h LAArray.C LARow.h LARow.C LAColumn.h LAColumn.C
if WANT_LIBRARY
include_HEADERS = Delta.h LAArray.h LAColumn.h LARow.h LAVar.h LRASolver.h
endif
Came to this modification by looking into the generic Makefile provided along with ibex sources to compile ibex projects:
SRCS=$(wildcard *.cpp)
BINS=$(SRCS:.cpp=)
CXXFLAGS := $(shell pkg-config --cflags ibex)
LIBS := $(shell pkg-config --libs ibex) -lblas -llapack
ifeq ($(DEBUG), yes)
CXXFLAGS := $(CXXFLAGS) -O0 -g -pg -Wall -frounding-math
else
CXXFLAGS := $(CXXFLAGS) -O3 -DNDEBUG -Wno-deprecated -frounding-math
endif
all: $(BINS)
% : %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $# $< $(LIBS)
clean:
rm -f $(BINS)
Ok, autoreconf works, as well as ./configure (though its output never talks about "ibex" which I find suspicious already). But make fails. Doesn't find the header:
../../../src/tsolvers/lrasolver/LRASolver.h:38:18: fatal error: ibex.h: No such file or directory
#include "ibex.h"
You're not using pkg-config correctly. You should use the PKG_CHECK_MODULES macro, see for reference https://autotools.io/pkgconfig/pkg_check_modules.html (full disclosure: I wrote that.)
You're also using AM_LDFLAGS incorrectly since libraries are not ldflags. You should use _LIBADD.
I want to finally get to know how to write an application which uses database. I chose C++, PostgreSQL and SOCI (SQL wrapper to C++). I use Xubuntu 11.4 and installed everyting which was necessary to run a simple program.
To use SOCI I installed:
1) libboost-dev
2) libpq-dev
3) libtool
4) SOCI, using this: http://soci.sourceforge.net/doc/backends/postgresql.html#required and I compiled SOCI with this command: cmake cmake -G "Unix Makefiles" -DWITH_BOOST=ON -DWITH_POSTGRESQL=ON ../
My simple program is veeery simple:
#include "soci-postgresql.h"
int main(int argc, char **argv){
soci::session sql(postgresql, "testDB");
return 0;
}
I compile it like this:
g++ test.cpp -lsoci_core -lsoci_postgresql -ldl -lpq
but it gives me error:
test.cpp:1:29: fatal error: soci-postgresql.h: No such file or
directory compilation terminated.
How to fix this, whats wrong? Did I miss to install something?
Some more infos:
/usr/local/include/soci$ ls
backend-loader.h postgresql soci-platform.h
blob-exchange.h prepare-temp-type.h soci-simple.h
blob.h procedure.h statement.h
boost-fusion.h ref-counted-prepare-info.h transaction.h
boost-gregorian-date.h ref-counted-statement.h type-conversion.h
boost-optional.h row-exchange.h type-conversion-traits.h
boost-tuple.h row.h type-holder.h
connection-pool.h rowid-exchange.h type-ptr.h
empty rowid.h unsigned-types.h
error.h rowset.h use.h
exchange-traits.h session.h use-type.h
into.h soci-backend.h values-exchange.h
into-type.h soci-config.h values.h
once-temp-type.h soci.h version.h
/usr/local/include/soci/postgresql$ ls
common.h soci-postgresql.h
/usr/local/lib$ ls
libCOS4.a libomniORB4.so.1
libCOS4.so libomniORB4.so.1.6
libCOS4.so.1 libomnithread.a
libCOS4.so.1.6 libomnithread.so
libCOSDynamic4.a libomnithread.so.3
libCOSDynamic4.so libomnithread.so.3.4
libCOSDynamic4.so.1 libsoci_core.a
libCOSDynamic4.so.1.6 libsoci_core.so
libomniCodeSets4.a libsoci_core.so.3.1
libomniCodeSets4.so libsoci_core.so.3.1.0
libomniCodeSets4.so.1 libsoci_empty.a
libomniCodeSets4.so.1.6 libsoci_empty.so
libomniConnectionMgmt4.a libsoci_empty.so.3.1
libomniConnectionMgmt4.so libsoci_empty.so.3.1.0
libomniConnectionMgmt4.so.1 libsoci_postgresql.a
libomniConnectionMgmt4.so.1.6 libsoci_postgresql.so
libomniDynamic4.a libsoci_postgresql.so.3.1
libomniDynamic4.so libsoci_postgresql.so.3.1.0
libomniDynamic4.so.1 pkgconfig
libomniDynamic4.so.1.6 python2.7
libomniORB4.a python3.2
libomniORB4.so
I also tried this one: g++ test.cpp -lsoci_core -lsoci_postgresql -ldl -lpq -I /usr/local/include/soci/postgresql and got the error:
g++ test.cpp -lsoci_core -lsoci_postgresql -ldl -lpq -I
/usr/local/include/soci/postgresql In file included from test.cpp:1:0:
/usr/local/include/soci/postgresql/soci-postgresql.h:27:26: fatal
error: soci-backend.h: No such file or directory compilation
terminated.
g++ test.cpp -Iyour_soci_dir -lsoci_core -lsoci_postgresql -ldl -lpq
your_soci_dir is directory with installed soci include files.
You need to set the search path with -I option.
g++ test.cpp -lsoci_core -lsoci_postgresql -ldl -lpq -I<path to headers>
^^^^^^^^^^^^^^^^^ Put the path
You need to provide all paths. I guess in your case, it should be like this :
g++ test.cpp -lsoci_core -lsoci_postgresql -ldl -lpq -I/usr/local/include/soci/postgresql -I/usr/local/include/soci
There is also another option (which is more used in makefiles) : to use pkg-config. Here you can find such example :
PROGRAM = test
PROGRAM_FILES = test.c
CFLAGS += -g $(shell pkg-config --cflags xmlsec1-nss)
LDFLAGS += -g
LIBS += $(shell pkg-config --libs xmlsec1-nss)
all: $(PROGRAM)
%: %.c
$(cc) $(PROGRAM_FILES) $(CFLAGS) $(LDFLAGS) -o $(PROGRAM) $(LIBS)
clean:
#rm -rf $(PROGRAM)
In your case, it would be something like this (not tested) :
PROGRAM = test
PROGRAM_FILES = test.cpp
CC=g++
CXXFLAGS += -g $(shell pkg-config --cflags soci_core) $(shell pkg-config --cflags soci_postgresql)
LDFLAGS += -g
LIBS += $(shell pkg-config --libs soci_core) $(shell pkg-config --libs soci_postgresql)
all: $(PROGRAM)
%: %.cpp
$(CC) $(PROGRAM_FILES) $(CFLAGS) $(LDFLAGS) -o $(PROGRAM) $(LIBS)
clean:
#rm -rf $(PROGRAM)
Ok guys, I found a solution on a polish programming website.
My new code (socitest.cpp):
#include <iostream>
#include <soci.h>
#include <postgresql/soci-postgresql.h>
int main(int argc, char **argv)
{
try
{
soci::session sql(soci::postgresql, "dbname=testDB");
}
catch (soci::postgresql_soci_error const & e)
{
std::cerr << "PostgreSQL error: " << e.sqlstate() << " " << e.what() << std::endl;
}
catch (std::exception const & e)
{
std::cerr << "Some other error: " << e.what() << std::endl;
}
return 0;
}
And I have to compile it :
g++ socitest.cpp -lsoci_core -lsoci_postgresql -ldl -lpq -I
/usr/local/include/soci -I /usr/include/postgresql -o socitest
It should compile but it might not run. If it's not running, I have to do sth more:
1) create soci.conf file:
touch /etc/ld.so.conf.d/soci.conf
2) edit my soci.conf with gedit:
gedit /etc/ld.so.conf.d/soci.conf
3) paste in soci.conf:
/usr/local/lib64
(for Xubuntu x64) or
/usr/local/lib
(for Xubuntu x32) and save file
4) run command:
ldconfig
5) run my compiled socitest like this: ./socitest and it's wooooorking !!! :D
Thanks all of you for helping me:)
Above example code can be compiled with just one command, without soci.conf and ldconfig:
g++ socitest.cpp -o socitest -I/usr/include/postgresql -I/usr/local/include/soci -L/usr/local/lib64/ \
-lsoci_core -lsoci_postgresql -Wl,-rpath=/usr/local/lib64/
For 32 bit unix use /usr/local/lib instead of /usr/local/lib64
I have been writing a plug-in for Maya with C++. The Makefile I use works fine on Snow Leopard, but does not in Lion. I am using the latest version of Maya 2012 in both cases. Here's the top of the error stack:
/Applications/Autodesk/maya2012/Maya.app/Contents/../../devkit/include/maya/OpenMayaMac.h:89:35: error:
AvailabilityMacros.h: No such file or directory
/Applications/Autodesk/maya2012/Maya.app/Contents/../../devkit/include/maya/OpenMayaMac.h:107:24: error:
sys/param.h: No such file or directory
/Applications/Autodesk/maya2012/Maya.app/Contents/../../devkit/include/maya/OpenMayaMac.h:114:40: error:
CoreServices/CoreServices.h: No such file or directory
This makes me think that these files are in a different location in Lion, but I do see them all in my /usr/include/ directory, just like Snow Leopard. Anyone have similar issues, ideas, suggestions?
The make file I use is below:
# NOTE: MAYA_LOCATION on Mac OS X points to Maya.app/Contents
MAYA_LOCATION = /Applications/Autodesk/maya2012/Maya.app/Contents
# Change location if a non standard install.
DEVKIT_LOCATION = $(MAYA_LOCATION)/../../devkit
C++ = g++
PREFERRED_ARCHITECTURE =
# Determine the architectures to build.
MAYABIN = ${MAYA_LOCATION}/bin/maya
MAYA_ARCHES = $(shell lipo -info $(MAYABIN) | sed 's/^.*://')
ifneq ($(PREFERRED_ARCHITECTURE),)
MAYA_ARCHES = $(filter $(PREFERRED_ARCHITECTURE),$(MAYA_ARCHES))
ifeq ($(MAYA_ARCHES),)
$(error $(MAYABIN) does not support the '$(PREFERRED_ARCHITECTURE)' architecture.)
endif
endif
ARCH_FLAGS = $(patsubst %,-arch %,$(MAYA_ARCHES))
CFLAGS = -DAW_NEW_IOSTREAMS -DCC_GNU_ -DOSMac_ -DOSMacOSX_ \
-DOSMac_MachO_ -DREQUIRE_IOSTREAM -fno-gnu-keywords -fpascal-strings -O3 \
$(ARCH_FLAGS) -D_LANGUAGE_C_PLUS_PLUS -isysroot /Developer/SDKs/MacOSX10.6.sdk \
-include $(MAYA_LOCATION)/../../devkit/include/maya/OpenMayaMac.h \
-shared
C++FLAGS = $(CFLAGS)
INCLUDES = -I. -I$(MAYA_LOCATION)/../../devkit/include
LDFLAGS = -framework Carbon -framework OpenGL -framework GLUT -lOpenMayaUI
LD = $(MAYA_LOCATION)/../../devkit/bin/mayald MAYA_ARCHES="$(MAYA_ARCHES)" MAYA_LOCATION="$(MAYA_LOCATION)"
all: VmExample.bundle
VmExampleNode.o: VmExampleNode.cpp
$(C++) -c VmExampleNode.cpp $(C++FLAGS) $(INCLUDES)
vmPluginMain.o: vmPluginMain.cpp
$(C++) -c vmPluginMain.cpp $(C++FLAGS) $(INCLUDES)
VmExample.bundle: VmExampleNode.o vmPluginMain.o
$(LD) -dynamic -bundle -o VmExample.bundle VmExampleNode.o vmPluginMain.o ../core/libVexample.o $(LDFLAGS)
same problem here; Managed to make it work by adding
-mmacosx-version-min=10.6
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk
to C++ Flags
I've just discovered FLTK and I made a makefile for my test. Here is my makefile:
################ template makefile ##############
# We don't know what compiler to use to build fltk on this machine - but fltk-config does...
CC = $(shell fltk-config --cc)
CXX = $(shell fltk-config --cxx)
# Set the flags for compiler: fltk-config knows the basic settings, then we can add our own...
CFLAGS = $(shell fltk-config --cflags)
CXXFLAGS = $(shell fltk-config --cxxflags) -I/System/Library/Frameworks/OpenGL.framework/Versions/A/
# We don't know what libraries to link with: fltk-config does...
LINKFLTK = $(shell fltk-config --ldstaticflags)
LINKFLTK_GL = $(shell fltk-config --use-gl --ldstaticflags) -lGLU
LINKFLTK_IMG = $(shell fltk-config --use-images --ldstaticflags)
# Possible steps to run after linking...
STRIP = strip
POSTBUILD = fltk-config --post # Required on OSX, does nothing on other platforms, so safe to call
TARGET = CompletedFile
# Define what your target application is called
all: $(TARGET)
# Define how to build the various object files... -snip-
# Now define how to link the final app - let's assume it needs image and OpenGL support
$(TARGET): MyWindow.o main.o
$(CXX) -o $# MyWindow.o main.o $(LINKFLTK_IMG) $(LINKFLTK_GL)
$(STRIP) $#
$(POSTBUILD) $# # only required on OSX, but call it anyway for portability
############### end #################
(Heres the object file code:)main.o: main.cpp MyWindow.h main.h
$(CXX) -c $< \
$(CXXFLAGS)
MyWindow.o: MyWindow.cpp MyWindow.h
$(CXX) -c $< \
$(CXXFLAGS)
Here is the error it gives me:
In file included from MyWindow.cpp:10:
MyWindow.h:14:20: error: GL/glu.h: No such file or directory
MyWindow.cpp: In member function ‘virtual void MyWindow::draw()’:
MyWindow.cpp:49: error: ‘gluPerspective’ was not declared in this scope
make: * [MyWindow.o] Error 1
(The code is irrelevant)
Depending on the fltk version you are using it has some of it's own openGL headers. I add the following lines to my include libraries:
-lfltk -lfltk_gl -lGL -lGLU
Overkill but it gets the job done.
The compiler can't find your GLU.h header. Adjust your #include or -I switch to point to the right location.