I'm trying to use the amalgamated version of jsoncpp in my own project. When using my makefile, it complains that it doesn't find json_tool.h:
input/jsoncpp.cpp:193:23: fatal error: json_tool.h: No such file or directory
#include "json_tool.h"
In my makefile I have:
jsoncpp.o: input/jsoncpp.cpp input/json/json.h
$(CXX) $(CXXFLAGS) -c input/jsoncpp.cpp $(LIBS)
with jsoncpp.cpp and json/json.h the ones created by the amalgamate.py script. What am I doing wrong?
You have not set up your include path properly
Add the following to your build command:
-I input/json/
Related
I'm trying to compile C++ project with gcc-make command but program giving this error. I already compiled Crypto++ and added include and lib folder but I dont know how to add this dir to gcc.
What should I do for fixing this "-lcrytopp" error?
I'm using makefile and this is line of 33-34.
$(TARGET): build $(OBJECTS)
$(CC) $(OBJECTS) -o $(TARGET) -lcryptopp
Error:
D:\Osman\CnC RA2\Mix\ccmix-crypto\ccmix-crypto>make
g++ src/mix_db_gamedb.o src/mix_db_gmd.o src/mix_header.o src/mix_db_lmd.o
src/mixid.o src/ccmix.o src/mix_file.o -o build/ccmix -lcryptopp
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32
/bin/ld.exe: cannot find -lcryptopp
collect2.exe: error: ld returned 1 exit status
Makefile:34: recipe for target 'build/ccmix' failed
make: *** [build/ccmix] Error 1
Crypto++ directory:
Compile error:
You haven't added the directory containing the library to your link line. It should be something like -Lxxx where xxx is the path to the directory containing the cryptopp library:
$(TARGET): build $(OBJECTS)
$(CC) $(OBJECTS) -o $(TARGET) -Lxxx -lcryptopp
(replace xxx with the directory containing the cryptopp library)
What should I do for fixing this "-lcrytopp" error?
When working from the Crypto++ build directory on Unix compatibles, the project does not use include and lib (as your picture shows). Everything is placed in the root directory (as your picture shows).
If you perform a make install, then the directories are setup, but it appears you did not install. I should also say that MinGW is not usually tested anymore because the project is abandoned, so I'm not sure where make install actually installs to on MinGW.
To fix the compile error, tweak your make recipe:
$(TARGET): build $(OBJECTS)
$(CXX) $(CXXFLAGS) -I. $(OBJECTS) ./libcryptopp.a -o $(TARGET)
The recipe above uses CXX (C++ compiler) rather than CC (C compiler); it uses CXXFLAGS (which should be something like -DNDEBUG -g2 -O2); it calls out the header path (-I.); and it links to the static library (./libcryptopp.a). Linking to the static library will avoid your next set of problems.
You can follow MadScientist's advice and use -LXXX and -lcryptopp. You might even add a runpath with -Wl,-rpath,D:\Osman\CnC RA2\Mix\ccmix-crypto\ccmix-crypto. But at the end of the day, using -L and -l causes a fair amount of trouble. Avoid the future problems by statically linking libcryptopp.a.
Also see GNUmakefile | Compiling and Linking on the Crypto++ wiki.
Your fist picture shows ipch and Win32 directories. That usually means you built the Crypto++ library with Visual Studio. Now you are building a program with GCC. You should not mix and match compilers like that. Nothing good will come of it.
Edit: whoops. Forgot to put the correct link while formatting
I'm following this tutorial, but I have gotten an error I can't fixed (I've looked at my code and then back at his for around 25 minutes. I'm sure it's not a typo anywhere)
C:\Users\badfitz66\Rastering>make
g++ makefile.cpp -o makefile
g++: error: CreateProcess: No such file or directory
make: *** [makefile] Error 1
The code of makefile.cpp is:
OBJ = main.o
INC = -I "./"
Rastering: $(OBJ)
g++ $(OBJ) -o Rastering.exe
rm -f $(OBJ)
main.o:
g++ -c main.cpp $(INC)
clean:
rm -f $(OBJ) Rastering
When you write -o makefile it means you want your C++ compiler to write its output to a file named makefile. Since Windows has case-insensitive file systems, that is a very bad idea because you will end up overwriting your Makefile, which should be named Makefile.
Also, you seem very confused about the difference between a Makefile and a C++ file. The file you posted is a Makefile, so it should be named Makefile, not makefile.cpp. You will need to have at least two files: Makefile, and main.cpp. If you want more help, you will have to show us the full contents of both of those files and the exact output you get when you run make.
The error g++: error: CreateProcess: No such file or directory is usually caused by your toolchain not being installed properly. You will need to install a C++ compiler that provides an executable named g++.exe and make sure that you add the directory with g++.exe in it to your PATH environment variable. The tutorial video you linked to ought to tell you how to do that.
A Makefile in the subdirectory of my project doesn't see the include path ONLY when it is used from the main Makefile of my project. I don't have much experience with Makefiles and a lot of what I've been reading is pretty confusing. Here is the layout of my directory (with what I have so far since I just started the project):
main/
Inventory/
Item.h
Item.cpp
Makefile
tools/
include/
json/
json.h
jsoncpp.cpp
Makefile
main.cpp
Makefile
Here is the Makefile in the main directory:
INCLUDE = -IInventory/
CC = g++
DEP = tools/jsoncpp.o Inventory/Item.o
Main: main.o $(DEP)
cd tools/ && make
cd Inventory/ && make
$(CC) -o Main main.o $(DEP) $(INCLUDE)
main.o main.cpp
$(CC) -c main.cpp $(INCLUDE)
Here is the Makefile in the tools directory:
INCLUDE = -Iinclude/
CC = g++
jsoncpp.o: jsoncpp.cpp
$(CC) -c jsoncpp.cpp $(INCLUDE)
When I call make from the tools/, it works just fine. But when I call make from the main directory I get this error:
g++ -c -o tools/jsoncpp.o tools/json.cpp
tools/jsoncpp.cpp:76:23: fatal error: json/json.h: No such file or directory
#include "json/json.h"
^
compilation terminated.
Now I partially believe that it can't find the include directory for whatever reason, but the first line in that error is fairly odd to me because of that weird gap between g++ and -c. Since my project will soon get pretty big, how can I fix this?
If it's in -I directive, it should be #include <json/json.h> otherwise #include "include/json/json.h"
EDIT: Include directory is taken from current directory, so in main/ you have to use -Itools/include
Solution: Implicit rules were used so correct variable CXXFLAGS+=$(INCLUDE) must be set for compilation. See: make manual
And the main problem is Main: main.o $(DEP) - files in DEP must exist already otherwise it'll use implicit rules. Later after that cd tools/ && make is done.
#include <json/json.h> <- preprocessor will search in all includes paths
see gcc Include Syntax :
#include <file> This variant is used for system header files. It searches for a file named file in a standard list of system
directories. You can prepend directories to this list with the -I
option (see Invocation).
#include "file" This variant is used for header files of your own program. It searches for a file named file first in the directory
containing the current file, then in the quote directories and then
the same directories used for . You can prepend directories to
the list of quote directories with the -iquote option.
I've strictly followed this documentation to install and use jsoncpp library in my project : jsoncpp README
But I still have this problem with my compilation:
g++ -W -Wall -Werror -c -o src/ModConnection.o src/ModConnection.cpp
src/ModConnection.cpp:15:23: fatal error: json/json.h: No such file or directory
compilation terminated.
It's happen when I'm trying to use #include <json/json.h>
Here is my Linux MAKEFILE :
CXX = g++
NAME = bin/server
SRCS = ./src/ModConnection.cpp\
./src/unixNetwork.cpp
OBJS = $(SRCS:.cpp=.o)
CXXFLAGS += -W -Wall -Werror
LDFLAGS = -L ./src/jsoncpp-src-0.5.0/buildscons/linux-gcc4.5.1/src/lib_json/libjson_linux-gcc-4.5.1_libmt.a -I src/jsoncpp-src-0.5.0/include
RM = rm -f
$(NAME) : $(OBJS)
$(CXX) $(LDFLAGS) -o $(NAME) $(OBJS)
all : $(NAME)
clean :
$(RM) $(OBJS)
fclean : clean
$(RM) $(NAME)
re : fclean all
.PHONY : all clean fclean re
Thanks for you help.
You're specifying the include directory for jsoncpp in your LDFLAGS variable, but those don't get used until you've already compiled the individual cpp files. You need to put the part -I src/jsoncpp-src-0.5.0/include somewhere in the flags which get added to the compile lines, such as CXXFLAGS.
To expand a bit, you're using implicit Make rules to build your individual .cpp files, then you have a specific target for building your application out of those objects.
See the GNU Make Catalog of Rules for more info, but the one you're using is here:
Compiling C++ programs
n.o is made automatically from n.cc, n.cpp, or n.C with a recipe of the form $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c. We encourage you to use the suffix ‘.cc’ for C++ source files instead of ‘.C’.
Edit: Now for your linking errors.
You're getting these problems because the linker can't find the actual implementations of the functions you're calling.
First, your -L directive needs to point to a folder, not a library. -L sets a search path for libraries. It should be set to the folder where the library the jsoncpp build was created. Next, you must link the library itself. That library name is gigantic, but adding -l json_linux-gcc-4.5.1_libmt to LDFLAGS should do the trick. -l (that's lower ell) sets an actual library to link.
I have a header in my project, called Core.h, that I use as a pre-compiled header:
$(CXX) $(CXX_CFLAGS) -x c++-header Core.h
Which creates a file named Core.h.gch
*#include "Core.h" is the first directive of every source file in the module.
On OS X, it works fine -- my project compiles fine & it compiles pretty fast.
On Linux however, 7 of my 100+ files give the following warning:
warning: Core.h.gch: too short to be a PCH file
Just like every other source file, #include "Core.h" is the first line of these files.
Has anyone ever come across this? Possible causes? Why would it only be a few files that include the PCH that would give the warning ?
I use gcc version 4.1.2 on Linux, 4.2.1 on OSX
Thanks!
EDIT:
Here is basically how I build the library:
.PHONY: all
all: $(MY_PCH) MYLIB.so MYLIB.a
MYLIB.so: $(MY_PCH) $(MY_OBJECTS)
$(CXX) $(MY_OBJECTS) $(CXX_LDFLAGS) -o $#
MYLIB.a: $(MY_PCH) $(MY_OBJECTS)
$(AR) $(ARFLAGS) $# $(MY_OBJECTS)
$(MY_PCH):
$(CXX) $(CXX_CFLAGS) -x c++-header Core.h
Are you using a parallel make? Possibly g++ is trying to read the .gch file while another instance is writing to it.