I'm trying to set up an OpenMP project using Clang (3.7.0) on my laptop running Linux Mint.
Now I've read that OpenMP is not supported right away so I followed the tutorial https://clang-omp.github.io/ to integrate OpenMP into Clang.
I've cloned the source code, set the environment variables and set the -fopenmp flag to my project, but I still get the error:
fatal error: 'omp.h' file not found
when building.
My guess is that I have set the environment variables wrong. Is there a way to check if I have put them in the right place? I have just copied them in the .bashrc file.
When I run locate omp.h I get:
/usr/include/re_comp.h
/usr/include/linux/ppp-comp.h
/usr/include/linux/seccomp.h
/usr/include/net/ppp-comp.h
/usr/include/openssl/comp.h
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/omp.h
/usr/lib/perl/5.18.2/CORE/regcomp.h
/usr/src/linux-headers-3.13.0-24/arch/arm/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/microblaze/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/mips/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/powerpc/include/uapi/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/s390/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/sh/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/sparc/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/x86/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/include/linux/ppp-comp.h
/usr/src/linux-headers-3.13.0-24/include/linux/seccomp.h
/usr/src/linux-headers-3.13.0-24/include/net/ipcomp.h
/usr/src/linux-headers-3.13.0-24/include/uapi/linux/ppp-comp.h
/usr/src/linux-headers-3.13.0-24/include/uapi/linux/seccomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/seccomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/crypto/pcomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/inet/ipcomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/inet6/ipcomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/isdn/ppp/bsdcomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/ppp/bsdcomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/xfrm/ipcomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/linux/ppp-comp.h
/usr/src/linux-headers-3.13.0-24-generic/include/linux/seccomp.h
Here is my makefile:
# Requires the following project directory structure:
# /bin
# /obj
# /src
# Use 'make remove' to clean up the whole project
# Name of target file
TARGET = main
CXX = clang++
CFLAGS = -std=c++11 \
-Weverything -Wall -Wextra -Wold-style-cast -Wpointer-arith -Wcast-qual \
-Wno-missing-braces -Wempty-body -Wno-error=uninitialized \
-Wno-error=deprecated-declarations -Wno-c++98-compat \
-pedantic-errors -pedantic \
-Os -fopenmp
LINKER = clang++ -o
LFLAGS = -Wall -Weverything -pedantic
SRCDIR = src
OBJDIR = obj
BINDIR = bin
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
INCLUDES := $(wildcard $(SRCDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
RM = rm -f
$(BINDIR)/$(TARGET): $(OBJECTS)
#$(LINKER) $# $(LFLAGS) $(OBJECTS)
#echo "Linking complete!"
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
#$(CXX) $(CFLAGS) -c $< -o $#
#echo "Compiled "$<" successfully!"
.PHONEY: prepare
prepare:
mkdir -p bin
mkdir -p obj
.PHONEY: clean
clean:
#$(RM) $(OBJECTS)
#echo "Cleanup complete!"
#$(RM) tmp_file-*
#echo "Temporary files removed!"
.PHONEY: remove
remove: clean
#$(RM) $(BINDIR)/$(TARGET)
#echo "Executable removed!"
.PHONEY: run
run:
./bin/$(TARGET)
OpenMP is well supported in Clang 3.7, but you might need to enable it see here.
OpenMP 3.1 is fully supported, but disabled by default. To enable it,
please use the -fopenmp=libomp command line option.
Also see Status of supported OpenMP constructs for more precision.
So you don't have to clone the clang-omp project any more.
What build system do you use for your project and what errors do you get when you compile?
If you use Makefile: do not forget to add the -fopenmp flag.
If you use CMake: you should also look for right OpenMP flags with the FindOpenMP module and add them accordingly.
If you still get the include error, then your omp.h header file may not be in the Clang default search path. So you should try to include the one that comes with GCC and add -I/usr/lib/gcc/x86_64-linux-gnu/4.8/include/.
So in your case you should add this line:
CFLAGS = -std=c+11 [etc...]
CFLAGS += -I/usr/lib/gcc/x86_64-linux-gnu/4.8/include/
LINKER = [etc...]
'omp.h' is a C header that comes with the "Mint" libgcc-[version]-dev (RPM-based OSes have this header in a different package, e.g. libgomp-*).
Example libgcc-4.8-dev: /usr/lib/gcc/x86_64-linux-gnu/4.8/include/omp.h
Solution: Install the version for your default GCC: gcc --version
libgcc-dev
In case the context is a build of Clang from source - one solution is to:
Ensure the openmp subproject is built by adding it to LLVM_ENABLE_PROJECTS at CMake invocation
Build that subproject with cmake --build . --target omp
Copy the generated omp.h from build/projects/openmp/runtime/src/omp.h to build/lib/clang/10.0.0/include, which is in the newly-built Clang's default search path.
I previously used the "add GCC's path to omp.h to every build command" approach, but I found this easier.
Related
I'm on kubuntu using g++ 7.5.0 / GNU make for C++. My file structure:
bin
| .o files
header
|archiver.h
source
|main.cpp
|archiver.cpp
makefile
I want my source files to be able to detect header files without having to do #include "../header/archiver.h". I've tried using:
g++ -I/header
but this does not work. I get the error:
g++: fatal error: no input files.
makefile that was requested
CC = g++
CFLAGS = -c -Wall
objects = bin/main.o bin/archiver.o
all : $(objects)
$(CC) -o build $(objects)
bin/%.o : source/%.cpp
$(CC) $(CFLAGS) $?
mv *.o bin
.PHONY : clean
clean :
rm -rf all $(objects)
The command
g++ -I<header-dir>
doesn't change any default settings for the g++ include search paths with subsequent calls, as you seem to assume.
You'll need to pass that compiler flag for each individual c++ call, which are issued by make according the rules defined in your makefile.
The latter is what you need to adapt, best using a pre-defined makefile variable like CXXFLAGS or CXXINCLUDES (check the GNU-make documentation for details).
For your specific case
CFLAGS = -c -Wall -I./header
should work.
For this reason I downloaded the C++ library VTK and made a local build in the build subdirectory on a OSX environment.
I would like to compile a project using this library (particularly I am using the class vtkSmartPointer) with Makefile.
Consider for example the following source code:
#include<iostream>
#include<vtkSmartPointer.h>
#include<vtkCallbackCommand.h>
int main()
{
vtkSmartPointer<vtkCallbackCommand> keypressCallback =
vtkSmartPointer<vtkCallbackCommand>::New();
std::cout<<"hello world\n";
return 0;
}
For the Makefile I started from the second answer in this post to which I aded VTK library path:
CXX = g++
# OpenCV trunk
CXXFLAGS = -std=c++11 \
-I ../VTK/Common/Core/ -I ../VTK/build/Common/Core/ -I ../VTK/build/Utilities/KWIML/ \
-I ../VTK/Utilities/KWIML/ \
-L../VTK/build/lib \
-lvtkCommon -lvtkFiltering -lvtkImaging -lvtkGraphics -lvtkGenericFiltering -lvtkIO
SOURCES := $(wildcard *.cpp)
OBJECTS := $(patsubst %.cpp,%.o,$(SOURCES))
DEPENDS := $(patsubst %.cpp,%.d,$(SOURCES))
# ADD MORE WARNINGS!
WARNING := -Wall -Wextra
# .PHONY means these rules get executed even if
# files of those names exist.
.PHONY: all clean
# The first rule is the default, ie. "make",
# "make all" and "make parking" mean the same
all: parking
clean:
$(RM) $(OBJECTS) $(DEPENDS) parking
# Linking the executable from the object files
parking: $(OBJECTS)
$(CXX) $(WARNING) $(CXXFLAGS) $^ -o $#
-include $(DEPENDS)
%.o: %.cpp Makefile
$(CXX) $(WARNING) $(CXXFLAGS) -MMD -MP -c $< -o $#
My environment variable DYLD_LIBRARY_PATH has the value ../cmake_bin_dir/instDir/lib:../VTK/build/lib/.
When I try to compile running make, I get the following error:
ld: library not found for -lvtkCommon
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What part of the Makefile or program or step in the process is not correct?
Thank you in advance.
The current VTK library does not contain libVtkCommon.so (see package contents section https://www.archlinux.org/packages/community/x86_64/vtk/). Are you looking for libVtkCommonCore.so? If that is the case you have to change -lvtkCommon to -lvtkCommonCore in your Makefile. The same seems to be the case for some of the other included libraries.
I am trying to compile a C++ program using make. I want it to read the source files from the src folder. Place the object files in the build folder, and put the exe in the bin folder.
I get the following error
/bin/wavfiletool.exe -g -O2 process_begin: CreateProcess(NULL,
/bin/wavfiletool.exe -g -O2, ...) failed. make (e=2): The system
cannot find the file specified.
UPDATE: The problem was I put g++ in for my compiler var instead of &(CC)...woops.
But now it says g++: fatal error: no input files
I am running make using a batch file that sets the environment variables.
SET PATH=C:\Make\GnuWin32\bin;C:\MinGW\bin
make %1
My makefile is as follows.
CC := g++
CFLAGS := -g -O2
BIN_DIR := /bin
BUILD_DIR := /build
SRC_DIR := /src
TARGET := wavfiletool.exe
SOURCES := $(wildcard $(SRC_DIR)/*.c)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
$(BIN_DIR)/$(TARGET): $(OBJECTS)
$(G++) $# $(CFLAGS) $(OBJECTS)
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
#$(CC) $(CFLAGS) -c $< -o $#
You haven't set the $(G++) variable anywhere so the recipe line for the $(BIN_DIR)/$(TARGET) target is trying to run $# instead of the compiler.
Also you are missing -o on that compilation line so were $(G++) set to g++ correctly you would end up running:
g++ /bin/wavfiletool.exe -g -O2 $(OBJECTS)
which likely isn't what you want.
That being said you probably don't want to be writing directly into /bin either. Did you mean ./bin for a bin directory in the local directory?
I have a makefile that I personally didn't write, and I'm not very good at bash scripting and makefiles in general, so forgive me for my lack of knowledge beforehand;
AS the title states I simply want to move my executables when compiled to a ../bin/ folder. My attempt at this (shamelessy copied from another post here on SO) is given below (i.e. i tried making a phony install which should move the files, but alas it doesnt."
CXX = g++
CC = g++
# Define preprocessor, compiler, and linker flags. Uncomment the # lines
# if you use clang++ and wish to use libc++ instead of libstd++.
CPPFLAGS = -std=c++11 -I..
CXXFLAGS = -g -O2 -Wall -W -pedantic-errors
CXXFLAGS += -Wmissing-braces -Wparentheses -Wold-style-cast
CXXFLAGS += -std=c++11
LDFLAGS = -g -L..
MV = mv
PROG_PATH = ../bin/
#CPPFLAGS += -stdlib=libc++
#CXXFLAGS += -stdlib=libc++
#LDFLAGS += -stdlib=libc++
# Libraries
#LDLIBS = -lclientserver
# Targets
PROGS = myserver myclient libclientserver.a
all: $(PROGS)
# Targets rely on implicit rules for compiling and linking
# The dependency on libclientserver.a is not defined.
myserver: myserver.o messagehandler.o server.o connection.o database_memory.o database_file.o
myclient: myclient.o connection.o server.o messagehandler.o
libclientserver.a: connection.o server.o
ar rv libclientserver.a connection.o server.o
ranlib libclientserver.a
# Phony targets
.PHONY: all install clean
all: $(PROGS) install
install: $(MV) $(PROGS) $(PROG_PATH)
# Standard clean
clean:
rm -f *.o $(PROGS)
# Generate dependencies in *.d files
%.d: %.cc
#set -e; rm -f $#; \
$(CPP) -MM $(CPPFLAGS) $< > $#.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $# : ,g' < $#.$$$$ > $#; \
rm -f $#.$$$$
# Include the *.d files
SRC = $(wildcard *.cc)
include $(SRC:.cc=.d)
So how would I best do this? The compiler says
make: *** No rule to make target `mv', needed by `install'. Stop.
A makefile rule consists of two parts, a declaration of the rule's dependencies and the commands to invoke.
The dependencies are listed on the first line of the rule after the colon and the commands to execute are listed on subsequent lines, all indented with tabs.
Your install rule needs to depend on the programs which you are moving and possibly the destination directory (you may want a rule that creates the destination), but not the mv utility itself as you don't need to build that.
install: $(PROGS)
mv $(PROGS) $(PROG_PATH)
Note that although I've used four spaces, the indentation needs to be a tab. As you don't (yet?) have a rule to make PROG_PATH, I've left it out of the dependency list.
Also note that with this rule, make will have to rebuild your programs if you invoke make twice as they will have moved. You way want to consider using cp or install instead of mv.
I don't know why, but at each new version of CGAL, the procedure to compile completely changes. So, it's not even possible to recompile old piece of code (6 months old) because it doesn't work like that anymore.
I'm frankly very tired of redoing all the makefile of my projects that use CGAL each time. This time, for libcgal8, I don't find any simple substitute. Here's the makefile I was normally using:
ifndef CGAL_MAKEFILE
CGAL_MAKEFILE = /usr/local/cgal/share/cgal/cgal.mk
endif
include $(CGAL_MAKEFILE)
LIBPATH = \
$(CGAL_LIBPATH)
LDFLAGS = \
$(LONG_NAME_PROBLEM_LDFLAGS) \
$(CGAL_LDFLAGS)
COMP=-frounding-math -fopenmp -std=c++0x -l json -L$(LIBPATH) $(LDFLAGS)
EXEC=../crender
all: main.o
g++ -fPIC main.o $(EXEC) $(COMP)
main.o: main.cpp ../common/common.hpp
g++ -c main.cpp $(COMP) -o main.o
So, what do I have to change to make it work again ? If possible, a solution that will survive to the future changes of CGAL.
If it can help, here's the kind of error that I get:
In function CGAL::Gmpq_rep::Gmpq_rep()':
main.cpp:(.text._ZN4CGAL8Gmpq_repC2Ev[_ZN4CGAL8Gmpq_repC5Ev]+0x14): undefined reference to__gmpq_init'
And I get these kind of errors for other functions like "__gmpg_add", "__gmpq_sub" and "__gmpq_mul."
SOLUTION:
You need to add "-lgmp" in the compilation instruction. It's sad that it's not done by default by the makefile provided by CGAL!
(Answered in the comments and in an Edit. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote:
You need to add "-lgmp" in the compilation instruction. It's sad that it's not done by default by the makefile provided by CGAL!
#sloriot Added:
Since January 2009 (release 3.4), CGAL is using cmake as build system. Since then, all include/link compiler flags are provided through the cmake mechanism (CGALConfig.cmake).
As mentioned above, now CGAL uses cmake as build system. While compiling CGAL example with cmake, I encountered similar problem. Solution is to add and link GMP library. Here is how its done for cmake: Cmake basic library linking problem
This is my makefile for linux and mac os x (no using cmake):
CPP := g++
OPCJE := -W -Wall -pedantic -O0 -Wno-c++11-extensions
BIBLIOTEKI := -lboost_math_c99 -lboost_thread -lm -lCGAL -lmpfr -lgmp
PISZ := echo -e
UNAME_S := $(shell uname -s)
on Mac os X some library are different name (brew install)
ifeq ($(UNAME_S),Darwin)
BIBLIOTEKI = -lboost_math_c99 -lboost_thread-mt -lm -lcgal -lmpfr -lgmp
PISZ = echo
endif
all source
SRC = $(wildcard *.cpp)
OBJ = $(addsuffix .o, $(basename $(SRC)))
BIN_DIR = ./bin
W_ZRODLA = $(wildcard *.cpp)
PROGRAMY = ${W_ZRODLA:%.cpp=$(BIN_DIR)/%}
$(BIN_DIR)/%: %.cpp
#mkdir -p ./bin
$(CPP) $(OPCJE) $< -o $# $(BIBLIOTEKI)
wszystkie: $(PROGRAMY)
#echo
clean:
rm -f ./bin/*
mem: 01
valgrind -v --tool=memcheck --leak-check=full ./01