I'm developing a project with boost and the preproc doesn't find the boost header files for a mysterious reason.
I'm on a xUbuntu 32 bits and I use g++ and boost 1.55.0
The error: main.cpp:1:26: fatal error: boost/bind.hpp: No such file or directory
If I comment this include, it's the next include who is not found so the problem isn't one file in particular.
The code:
#include "boost/bind.hpp" // just to be sure I test with "" and <>
#include <boost/asio.hpp>
#include <sys/types.h>
The makefile:
NAME = myProject
INSTALL_DIR = /usr/local/bin
FILES_DIR = /etc/myProject
RC_FILE = ./scripts/myproject.rc
SRC = main.cpp
OBJ = $(SRC:.cpp=.o)
CC = g++
IFLAGS = -I./boost/
LFLAGS = -pthread -L./boost/stage/lib/ -lboost_system-mt -lboost_regex-mt -lboost_filesystem-mt
RM = rm -f
all : $(OBJ)
$(CC) -o $(NAME) $(OBJ) $(IFLAGS) $(LFLAGS)
install :
mkdir -p $(INSTALL_DIR)
mkdir -p $(FILES_DIR)
cp $(NAME) $(INSTALL_DIR)
cp $(RC_FILE) /etc/init.d/
insserv $(RC_FILE)
remove :
insserv --remove $(RC_FILE)
clean :
find . -name "*~" -exec rm {} \;
find . -name "*.o" -exec rm {} \;
fclean : clean
$(RM) $(NAME)
re : clean all
.PHONY : install remove clean fclean
The main.cpp and the makefile are in whatever/myproject/
The boost library is in whatever/myproject/boost/
The boost libs (.a and .so) are in whatever/myproject/boost/stage/lib/
The boost headers are in whatever/myproject/boost/boost/
I've searched for about 2 hours, tried everything I can think of without success, so thank you very much in advance to the person who can resolve this problem.
Edit:
Bidule0hm make -n
g++ -c -o main.o main.cpp
g++ -o myProject main.o -I./boost/ -pthread -L./boost/stage/lib/ -lboost_system-mt -lboost_regex-mt -lboost_filesystem-mt
I've finally solved the problem by installing boost with apt-get instead of using it locally in the project folder.
Other answer that helped me here
Can you run make -n or make V=1 and post the output?
Second Post:
I think the include folders have to come before the -o on g++. Can you replace $(CC) -o $(NAME) $(OBJ) $(IFLAGS) $(LFLAGS)
with $(CC) -c $(IFLAGS) -o $(NAME) $(OBJ) $(LFLAGS)
A sample line from my project looks like:
g++ -c -g -I.. -I/usr/include/boost -std=c++11 "build/Debug/main.o.d" -o build/Debug/main.o main.cpp
First post:
For laughs, try doing -I/full/path/to/boost.
Often with these issues, its more of a case of the "." not being the directory you think it is.
Please also post up what platform you're on(windows, Linux), and the makefile :)
Related
I am trying to write a make file for the following program
MY file/folder structure is as follows
Folder/File structure
./demo/utilities.c
./demo/utilities.h
./demo/makefile
./include/GeographicLib/UTMUPS.h
./include/GeographicLib/Constant.h
./include/GeographicLib/xxxxxxx
in the file utilities.h
#include <GeographicLib/UTMUPS.h>
in the file UTMUPS.h
#include <GeographicLib/Constant.h>
in the makefile
# preprocessor
PREPROC_FLAGS += -DEIGEN_DONT_ALIGN_STATICALLY
INC_XTRA_DIR = ../include
CC=g++
CPPFLAGS= $(PREPROC_FLAGS)
CFLAGS=-O2 -g -Wall -W -I$(INC_XTRA_DIR)
CXXFLAGS=-O2 -g -Wall -W -fpic -std=c++11
# short hand
OBJDIR=obj
Utilities_h = utilities.h GeographicLib/UTMUPS.hpp
utilities.o: utilities.c $(Utilities_h)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $#
all: $(FINAL_TARGET)
$(FINAL_TARGET): $(OBJ)
$(CC) -g -o $# $^ $(LDFLAGS)
ifneq ($(wildcard ../databases/.),)
cp $# ../
endif
TargetList = $(FINAL_TARGET)
clean:
rm -f $(TargetList) *.o *~
echo Clean done.
The question I want to ask is
When I compile the following project, it say it can't find "#include 'GeographicLib/UTMUPS.h'". in the utilities.h. what should the naming be in this case. My thought is that by adding -I$(INC_XTRA_DIR), or ../include ... it should search for GeographicLib/UTMUPS.h
what about the file that UTMUPS.h is dependent on(in this case Constant.h), what should be the addressing
Edit: I run make at the root directory... maybe that's the reason for the error.
THanks
I'm trying to create an opengl project for this tutorial, and I can't get my program to compile.
The current problem here is that every glfw functions are undefined, but they exist in glfw3.h.
The glfw3 files are from the glfw download page (x64 version).
Here is a copy of the logs:
make
=== SRC ===
src/glad.c src/main.cpp
=== OBJ ===
bin/glad.o bin/main.o
===== Creating file bin/glad.o ===
C:/cygnus/cygwin-b20/H-i586-cygwin32/bin/mkdir -p bin/
C:/MinGW/bin/g++ -I./include -o bin/glad.o -c src/glad.c
===== Creating file bin/main.o ===
C:/cygnus/cygwin-b20/H-i586-cygwin32/bin/mkdir -p bin/
C:/MinGW/bin/g++ -I./include -o bin/main.o -c src/main.cpp
C:/MinGW/bin/g++ -L./libs -o build/program.exe bin/glad.o bin/main.o -lglfw3
bin/main.o:main.cpp:(.text+0xc): undefined reference to `glfwInit'
collect2.exe: error: ld returned 1 exit status
make: *** [program.exe] Erreur 1
I'm using the following main.cpp file:
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
int main(int argc, char** argv){
glfwInit();
return 0;
}
And the following makefile:
CXX = C:/MinGW/bin/g++
FAKEPATH = C:/cygnus/cygwin-b20/H-i586-cygwin32/bin/
CXXFLAGS = -W -Wall -ansi -Wno-deprecated
LDLIBS = -lglfw3
TARGET = program.exe
LIB_DIR = -L./libs
INC_DIR = -I./include
SRC = $(shell $(FAKEPATH)find src/ -type f \( -iname \*.cpp -o -iname \*.c \))
OBJ = $(patsubst src/%,bin/%,$(addsuffix .o, $(basename $(SRC))))
all: directories $(TARGET)
test:
echo $(FAKEPATHEXISTS)
directories:
#$(FAKEPATH)echo === SRC ===
#$(FAKEPATH)echo $(SRC)
#$(FAKEPATH)echo === OBJ ===
#$(FAKEPATH)echo $(OBJ)
#$(FAKEPATH)mkdir -p bin
#$(FAKEPATH)mkdir -p build
compileAndRun: all
build/$(TARGET)
$(TARGET): $(OBJ)
$(CXX) $(LDFLAGS) $(LIB_DIR) -o build/$# $^ $(LDLIBS)
bin/%.o: src/%.c
#$(FAKEPATH)echo ===== Creating file $# ===
$(FAKEPATH)mkdir -p $(dir $#)
$(CXX) $(INC_DIR) -o $# -c $<
bin/%.o: src/%.cpp
#$(FAKEPATH)echo ===== Creating file $# ===
$(FAKEPATH)mkdir -p $(dir $#)
$(CXX) $(INC_DIR) -o $# -c $<
clean:
#$(FAKEPATH)rm -rf bin/
cleaner: clean
#$(FAKEPATH)rm -rf build/
And finally, my files are sorted like this:
I'm using MinGW for g++ and cygwin for the linux commands.
Any help or try would be really appreciated ! (I really don't know where the problem came from)
Thanks !
Note: I already searched on google a lot without finding any working solution (including several stack overflow questions)
I found a solution to this.
The first things I had to do is add #define GLFW_DLL in my main.cpp.
After doing this I had the error Undefined reference to '_imp__glfwInit'. To solve this error I had to remove the *.a files in my /libs, and then I moved my .dll file to the root of the project (To avoid a missing dll error).
I'm trying to link my program with boost libraries using makefile with cygwin. Here is my makefile:
CXX = g++
CXXFLAGS = -Wno-signed-compare -Wall -std=c++11 -funsigned-char -I /cygdrive/e/boost/include/boost-1_55/boost
LNKFLAGS = -L cygdrive/e/boost/lib
SRCDIR = src
OUTDIR = bin
EXEC = $(OUTDIR)/prg
SOURCES = $(wildcard src/*.cpp)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OUTDIR)/%.o)
all: $(EXEC)
$(EXEC): $(OBJECTS)
$(CXX) $(LNKFLAGS) $(OBJECTS) -o $(EXEC) -l boost_thread
$(OBJECTS): $(OUTDIR)/%.o : $(SRCDIR)/%.cpp
mkdir -p $(OUTDIR)
$(CXX) $(CXXFLAGS) -c -O3 $< -o $#
clean:
rm -rf $(OUTDIR)
.PHONY: clean
Result:
$ make
g++ -L cygdrive/e/boost/lib bin/test.o -o bin/prg -l boost_thread
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lboost_thread
What's wrong? What should I specify?
In your Makefile the library search path is relative, but should be absolute in this case.
LNKFLAGS = -L/cygdrive/e/boost/lib
Check if /cygdrive/e/boost/lib really contains Boost libraries built with the GCC toolchain.
libboost_thread.a or libboost_thread.so will work.
Libraries built with the Visual C++ toolchain ending with .lib or .dll will not work.
Check if the filename matches.
-lboost_thread requires that the library is named either libboost_thread.a or libboost_thread.so.
libboost_thread-mt.a or the like will not work.
You may find my answer to a related question helpful.
I can't figure out how to get my Makefile to compile a group of cpp files using the -lpthread. The problem is occurring with g++ *.cpp -c. My functions (Which are in external files), can't find pthread_exit. What is the correct way to do this?
#
#Makefile for producerConsumer
#
RM = rm -f
#SRC = producer.cpp consumer.cpp
#OBJ = $(SRC:.cpp=.o)
TESTNAME = test
TESTSRC = main.cpp
#
retest: re test
test:
g++ *.cpp -c
g++ *.o -o $(TESTNAME) -lpthread
clean:
-$(RM) *.o
-$(RM) *~
-$(RM) \#*
-$(RM) *.core
fclean: clean
-$(RM) $(TESTNAME)
-$(RM) *.o
re: fclean
It looks like you're using Linux, so use -pthread instead of -lpthread, and make sure to add it to both the compilation and linking commands. The -pthread option will make sure pthread support is activated while (pre-)compiling your code, and will ensure that the correct libraries are linked in properly.
Additionally, make sure you've included <pthread.h> in any compilation unit that uses pthread functions, so they all look for the correct symbols.
Here's a sample makefile :
CXX = g++
LD = g++
CXXFLAGS = -Wall -pthread
LDFLAGS = -pthread
SOURCES = main.cpp
OBJECTS = $(SOURCES:.cpp=.o)
BINARY = test
all : $(SOURCES) $(BINARY)
$(BINARY) : $(OBJECTS)
$(LD) $(LDFLAGS) $^ -o $#
.cpp.o :
$(CXX) $(CXXFLAGS) -c $< -o $#
.PHONY : clean
clean :
rm -f *.o $(BINARY)
I am working on a C++ project and I need to use libtcl.
I am running Ubuntu 12.10 32bits and there is a problem when I try to compile my files :
g++ -o executable executable.o -L/usr/share/tcltk -lncurses -ltcl
/usr/bin/ld: cannot find -ltcl
libncurses is found but not libtcl...
Do you have any idea?
I have seen that libtcl8.4.so.0 libtcl8.5.so.0 exist in /usr/lib
The makefile that I am using looks like this :
CC = g++
CFLAGS = -g
LDFLAGS =
EXEC = executable
LIB = -L/usr/share/tcltk -lncurses -ltcl
all: executable
executable: executable.o
$(CC) $(LDFLAGS) -o $(EXEC) executable.o $(LIB)
executable.o: executable.cpp
$(CC) $(CFLAGS) -c executable.cpp
clean:
rm -f executable executable.o
Thanks
(Answered in a comment. See Question with no answers, but issue solved in the comments (or extended in chat) )
#soon wrote:
just create symlink to the your library like so #ln -s /usr/lib/libtcl8.5.so.0 /usr/lib/libtcl.so