I'm working in windows and want to send data from C++ to Matlab. I've gotten the impression this is done most easy creating a makefile. Therefore I've installed cygwin to use the make command.
My makefile is as follows:
CXX = g++
CFLAGS = -O3 -I /cygdrive/c/Program\ Files/MATLAB/R2011a/extern/include
LIBS = -L /cygdrive/c/Program\ Files/MATLAB/R2011a/extern/lib/win64/microsoft/
LIBS2 = -L /cygdrive/c/Program\ Files/MATLAB/R2011a/extern/lib/win64/microsoft/libmx.lib
LDFLAGS = -leng -lmx
RKspace2d: RKspace2d.o
$(CXX) -o $# $^ $(LDFLAGS) $(LIBS)
RKspace2d.o: RKspace2d.cpp
$(CXX) -c $(CFLAGS) $(LIBS) $<
# $# name of the target
# $^ name of all prerequisites with duplicates removed
# $< name of the first prerequisite
When I type in "make" in the cygwin terminal, being in the right directory I get the following error:
$ make
g++ -o RKspace2d RKspace2d.o -leng -lmx -L /cygdrive/c/Program\ Files/MATLAB/R2011a/extern/lib/win64/microsoft/
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -leng
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lmx
collect2: ld returnerede afslutningskoden 1
makefile:8: recipe for target `RKspace2d' failed
make: *** [RKspace2d] Error 1
I believe the path is correct since both libeng.lib and libmx.lib are contained in the microsoft folder.
Hope you guys can help
Thomas
Related
I'm trying to build a python wrapper using the following Makefile:
CC=/usr/local/opt/llvm/bin/clang
OS_NAME=$(shell uname -s)
ifeq ($(OS_NAME),Linux)
LAPACKLDFLAGS=/usr/lib64/atlas/libsatlas.so # single-threaded blas
#LAPACKLDFLAGS=/usr/lib64/atlas/libtatlas.so # multi-threaded blas
#BLAS_THREADING=-D MULTITHREADED_BLAS # remove this if wrong
endif
ifeq ($(OS_NAME),Darwin) # Mac OS X
LAPACKLDFLAGS=-framework Accelerate # for OS X
endif
LAPACKCFLAGS=-Dinteger=int $(BLAS_THREADING)
STATICLAPACKLDFLAGS=-fPIC -Wall -g -fopenmp -static -static-libstdc++ /home/lear/douze/tmp/jpeg-6b/libjpeg.a /usr/lib64/libpng.a /usr/lib64/libz.a /usr/lib64/libblas.a /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libgfortran.a /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libquadmath.a # statically linked version
CFLAGS= -fPIC -Wall -g -std=c++11 $(LAPACKCFLAGS) -fopenmp -DUSE_OPENMP -O3
LDFLAGS=-fPIC -Wall -g -ljpeg -lpng -fopenmp
CPYTHONFLAGS=-I/usr/include/python2.7
SOURCES := $(shell find . -name '*.cpp' ! -name 'deepmatching_matlab.cpp')
OBJ := $(SOURCES:%.cpp=%.o)
HEADERS := $(shell find . -name '*.h')
all: deepmatching
.cpp.o: %.cpp %.h
$(CC) -o $# $(CFLAGS) -c $+
deepmatching: $(HEADERS) $(OBJ)
$(CC) -o $# $^ $(LDFLAGS) $(LAPACKLDFLAGS)
deepmatching-static: $(HEADERS) $(OBJ)
$(CC) -o $# $^ $(STATICLAPACKLDFLAGS)
python: $(HEADERS) $(OBJ)
# swig -python $(CPYTHONFLAGS) deepmatching.i # not necessary, only do if you have swig compiler
/usr/local/opt/llvm/bin/clang $(CFLAGS) -c deepmatching_wrap.c $(CPYTHONFLAGS)
/usr/local/opt/llvm/bin/clang -shared $(LDFLAGS) $(LAPACKLDFLAGS) deepmatching_wrap.o $(OBJ) -o _deepmatching.so $(LIBFLAGS)
clean:
rm -f $(OBJ) deepmatching *~ *.pyc .gdb_history deepmatching_wrap.o _deepmatching.so deepmatching.mex???
Previously, CC was set to g++, however, when I tried to build it like this, I'd get "ERROR: clang: error: unsupported option '-fopenmp".
Now I installed "brew install llvm" as this comes with the -fopenmp option. The unsupported error is resolved for now, but now the compiler doesn't seem to find a header file:
(base) MacBook-Pro-van-Brent:deepmatching BrentDeHauwere$ make python
/usr/local/opt/llvm/bin/clang -o hog.o -fPIC -Wall -g -std=c++11 -Dinteger=int -fopenmp -DUSE_OPENMP -O3 -I/usr/local/opt/llvm/include -c hog.cpp
In file included from hog.cpp:18:
In file included from ./std.h:20:
/usr/local/opt/llvm/bin/../include/c++/v1/math.h:300:15: fatal error: 'math.h' file not found
#include_next <math.h>
^~~~~~~~
1 error generated.
make: *** [hog.o] Error 1
I've tried setting options (I might have set them incorrectly) like -L/usr/local/opt/llvm/lib and -I/usr/local/opt/llvm/include, but no result so far. Any idea how I could point the compiler to the right direction for the header files?
Try running xcode-select —install in your terminal. This installs the xcode command line tools which should also install system headers files (as part of the macos sdk) and set your system include paths.
I have this folder structure:
Project_folder
Project_folder/Ml.app (folder)
Project_folder/Ml.lib (folder)
In the folder Ml.lib I've created a shared library named ml.so
Now I want to link to the client application inside the Ml.app folder.
Here's my makefile:
LIBS = -L ../Ml.lib -l ml
INCLUDES = ../Ml.lib
CXXLAGS = -Wall -I$(INCLUDES)
OBJFILES = main.o
TARGET = mltest
all: $(TARGET)
$(TARGET): $(OBJFILES)
$(CXX) $(CXXLAGS) -o $(TARGET) $(OBJFILES) $(LIBS) $(LDFLAGS)
clean:
rm -f $(OBJFILES) $(TARGET) *~
but when I try to build it I get
g++ -Wall -I../Ml.lib -o mltest main.o -L ../Ml.lib -l ml
/usr/bin/ld: cannot find -lml collect2: error: ld returned 1 exit
status make: *** [Makefile:8: mltest] Error 1
The option -L specifies an additional search directory for libraries. -l looks for an additonal library. Use:
LIBS = -L .. -l Ml
For context, I'm trying to compile source to a 32-bit executable for Windows using a Linux machine. I'm using the current mingw-w64 via apt-get. Here's the project I'm trying to compile ftp://ftp.thegpm.org/projects/tandem/source. More specifically the 17-02-01 zip files contain the source I'm interested in.
My first attempt was to just edit with the Makefile_ubuntu under the tandem-linux and swap out the gcc with the one provided by mingw and fix header reference issues that cropped up by adding #includes to .cpp files that threw errors. Super hacky. Can someone show me a brighter path?
Here's the makefile I'm using:
#makefile for c++ programs
#change the name of the executable to use for "any" project
EXECUTABLE = ../bin/tandem.exe
#EXECUTABLE = ../bin/p3.exe
LINKCC = $(CXX)
#CXXFLAGS denotes flags for the C++ compiler
CXX = /usr/bin/i686-w64-mingw32-g++-win32
#uncomment this line if you are using gcc 4.x
CXXFLAGS = -m32 -std=gnu++11
#CXXFLAGS = -w -O2 -DGCC4_3
#CXXFLAGS = -w -O2 -DGCC4_3 -DX_P3
#ubuntu 64 bit version
#LDFLAGS = -L/usr/lib/x86_64-linux-gnu/libexpat.a
LDFLAGS = -lpthread -lm -L/usr/lib/x86_64-linux-gnu/libexpat.a
#LDFLAGS = -lpthread -L/usr/lib -lm -lexpat
SRCS := $(wildcard *.cpp)
OBJS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
DEPS := $(patsubst %.o,%.d,$(OBJS))
all: $(EXECUTABLE)
#define the components of the program, and how to link them
#these components are defined as dependencies; that is they must be up-to-date before the code is linked
$(EXECUTABLE): $(DEPS) $(OBJS)
$(LINKCC) $(CXXFLAGS) -o $(EXECUTABLE) $(OBJS) $(LDFLAGS)
#specify the dep files depend on the cpp files
%.d: %.cpp
$(CXX) -M $(CXXFLAGS) $< > $#
$(CXX) -M $(CXXFLAGS) $< | sed s/\\.o/.d/ > $#
clean:
-rm $(OBJS) $(EXECUTABLE) $(DEPS) *~
explain:
#echo "The following info represents the program:"
#echo "Final exec name: $(EXECUTABLE)"
#echo "Source files: $(SRCS)"
#echo "Object files: $(OBJS)"
#echo "Dep files: $(DEPS)"
depend: $(DEPS)
#echo "Deps are now up-to-date."
-include $(DEPS)
And here is the error(s):
sudo make -f Makefile_ubuntu
/usr/bin/i686-w64-mingw32-g++-win32 -m32 -std=gnu++11 -o ../bin/tandem.exe tandem.o p3mprocess.o saxmzdatahandler.o mspectrumcondition.o masscalc.o mprocess.o mreport.o mscore_tandem.o loadmspectrum.o mplugin.o msequenceserver.o saxtaxhandler.o msequencecollection.o mscore.o mrefine.o xmltaxonomy.o mbiomlreport.o saxtandeminputhandler.o saxhandler.o msequtilities.o base64.o saxmodhandler.o mtermmods.o xmlparameter.o saxsaphandler.o saxmzxmlhandler.o saxmzmlhandler.o mxxcleavage.o p3msequenceserver.o mzid_report.o saxbiomlhandler.o p3.o mpmods.o saxgamlhandler.o stdafx.o MSNumpress.o mpam.o -lpthread -lm -L/usr/lib/x86_64-linux-gnu/libexpat.a
saxhandler.o:saxhandler.cpp:(.text+0x100): undefined reference to `XML_ParserCreate'
saxhandler.o:saxhandler.cpp:(.text+0x11d): undefined reference to `XML_SetUserData'
saxhandler.o:saxhandler.cpp:(.text+0x13b): undefined reference to `XML_SetElementHandler'
saxhandler.o:saxhandler.cpp:(.text+0x151): undefined reference to `XML_SetCharacterDataHandler'
saxhandler.o:saxhandler.cpp:(.text+0x1cf): undefined reference to `XML_ParserFree'
saxhandler.o:saxhandler.cpp:(.text+0x344): undefined reference to `XML_Parse'
saxhandler.o:saxhandler.cpp:(.text+0x37f): undefined reference to `XML_Parse'
saxhandler.o:saxhandler.cpp:(.text+0x3bd): undefined reference to `XML_GetErrorCode'
saxhandler.o:saxhandler.cpp:(.text+0x3d4): undefined reference to `XML_GetCurrentLineNumber'
collect2: error: ld returned 1 exit status
Makefile_ubuntu:33: recipe for target '../bin/tandem.exe' failed
make: *** [../bin/tandem.exe] Error 1
You are (incorrectly) linking with /usr/lib/x86_64-linux-gnu/libexpat.a which is a Linux library (in ELF format). You need to get some Windows version of it.
BTW -L/usr/lib/x86_64-linux-gnu/libexpat.a is incorrect. Since -L should give a directory not a library to link
At last, recent versions of Windows might have WSL which could be useful to you (you'll compile a Linux, mostly statically linked, executable, and it might run on the command line on Windows).
I have a problem with the following makefile in Windows. Although it worked in Linux, I get an error now using MinGW in Windows.
I checked the article on this page: Compile using MakeFile in Window, but I still have no success.
CC = c++
CFLAGS = -Wall -g
ODIR = /OBJ
CFILES := $(wildcard SRC/*.cpp)
OFILES := $(addprefix OBJ/,$(notdir $(CFILES:.cpp=.o)))
meshl: $(OFILES)
$(CC) $(CFLAGS) -o $# $(OFILES)
OBJ/%.o: SRC/%.cpp
$(CC) $(CFLAGS) -c $< -o $#
clean:
rm -f OBJ/*.o
When I try to compile it in the command prompt, the following message appears:
OBJ/mpoint.o: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
makefile:9: recipe for target 'meshl' failed
make: ***[meshl] Error 1
Thanks for your time and help!
I'm following this SDL tutorial to try and make use of some SDL extension libraries. My code is identical to theirs but I am still unable to make the file which leads me to believe the problem is in my makefile which looks like this:
CXX = g++
# Update these paths to match your installation
# You may also need to update the linker option rpath, which sets where to look for
# the SDL2 libraries at runtime to match your install
SDL_LIB = -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image
SDL_INCLUDE = -I/usr/local/include
# You may need to change -std=c++11 to -std=c++0x if your compiler is a bit older
CXXFLAGS = -Wall -c -std=c++11 $(SDL_INCLUDE)
LDFLAGS = $(SDL_LIB)
EXE = SDL_Lesson3
all: $(EXE)
$(EXE): main.o
$(CXX) $< $(LDFLAGS) -o $#
main.o: main.cpp
$(CXX) $(CXXFLAGS) $< -o $#
clean:
rm *.o && rm $(EXE)
That makefile worked fine for previous examples. The only thing that has changed in this example is line 5 where I added -lSDL2_image as per the tutorial. When I try make the file I get the following traceback:
rony#comet:~/Documents/cpp/helloworld/lesson3$ make
g++ main.o -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image -o SDL_Lesson3
/usr/bin/ld: cannot find : No such file or directory
collect2: error: ld returned 1 exit status
make: *** [SDL_Lesson3] Error 1
Is there an error with my makefile? Have I not installed the library correctly?
The problem is this rogue comma:
SDL_LIB = -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image
^
causing the linker to look for libraries in a non-existent directory with an empty name, as well as /usr/local/lib. Removing the comma should fix it.