Include file downloaded by Bazel http_file - c++

I'm using Bazel to build my project. I'd like to use the single-header test framework, Catch v2. I decided to use the http_file rule to make Bazel download the catch header. My WORKSPACE file looks like this:
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(
name = "catch",
downloaded_file_path = "catch.hpp",
sha256 = "cc6cc272cf84d8e10fb28f66f52584dedbb80d1234aae69e6a1027af4f31ae6f",
urls = ["https://github.com/catchorg/Catch2/releases/download/v2.4.2/catch.hpp"],
)
According to the doc, the test depends on the generated package like this:
cc_test(
name = "my_test",
srcs = ["#catch//file", "my_test.cc"]
)
The test file my_test.cc can't get any simpler:
#include "catch.hpp"
However, I get the following error:
$ bazel test --config=opt -s //...
WARNING: [...]/BUILD:25:10: in srcs attribute of cc_test rule //test:my_test: please do not import '#catch//file:catch.hpp' directly. You should either move the file to this package or depend on an appropriate rule there
SUBCOMMAND: # //test:my_test [action 'Compiling test/my_test.cc']
(cd [...] && \
exec env - [...] \
/usr/bin/gcc
-U_FORTIFY_SOURCE -fstack-protector -Wall -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF [...].d '-frandom-seed=[...].o' -fPIC
-iquote .
-iquote bazel-out/k8-fastbuild/genfiles
-iquote bazel-out/k8-fastbuild/bin
-iquote external/bazel_tools
-iquote bazel-out/k8-fastbuild/genfiles/external/bazel_tools
-iquote bazel-out/k8-fastbuild/bin/external/bazel_tools
-fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c test/my_test.cc
-o [...].o)
ERROR: [...]/BUILD:23:1: C++ compilation of rule '//test:my_test' failed (Exit 1)
test/my_test.cc:1:28: fatal error: catch.hpp: No such file or directory
compilation terminated.
[...]
FAILED: Build did NOT complete successfully
Creating a cc_library wrapper, or including catch/catch.hpp, catch/file/catch.hpp produces the same error.

By default, files downloaded by http_file can be included as:
#include "external/<name>/file/<file_name>"
In this specific case:
#include "external/catch/file/catch.hpp"
However, this include path is ugly, it should be wrapped by a cc_library.
Furthermore, compiling the full catch header file for each test will make the build slow. According to the catch docs, the implementation part of the catch header should be compiled separately. Like this:
test/BUILD:
cc_library(
name = "catch",
hdrs = ["#catch//file"],
srcs = ["catch.cpp"],
visibility = ["//visibility:public"],
strip_include_prefix = "/external/catch/file",
include_prefix = "catch",
linkstatic = True, # otherwise main() will could end up in a .so
)
cc_test(
name = "my_test",
deps = ["//test:catch"],
srcs = ["my_test.cc"],
)
test/catch.cpp:
#define CATCH_CONFIG_MAIN
#include "catch/catch.hpp"
test/my_test.cc:
#include "catch/catch.hpp"
TEST_CASE("my_test", "[main]") { /* ... */ }
This way catch.cpp will not be re-compiled if only my_test.cc changes, saving precious seconds.

Related

I can't properly add external dependency with bazel

I trying to test "Hello World" C++ project with Bazel.
I have the following project structure:
WORKSPACE
/dependencies
BUILD
BUILD.gtest
/test
BUILD
WORKSPACE has the following structure:
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# gtest
http_archive(
name = "gtest",
url = "https://github.com/google/googletest/archive/release-1.10.0.zip",
sha256 = "94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91",
build_file = "#//dependencies:BUILD.gtest",
strip_prefix = "googletest-release-1.10.0",
)
BUILD.gtest has the following structure:
cc_library(
name = "main",
srcs = glob(
["src/*.cc"],
exclude = ["src/gtest-all.cc"]
),
hdrs = glob([
"include/**/*.h",
"src/*.h"
]),
copts = ["-Iexternal/gtest/include"],
linkopts = ["-pthread"],
visibility = ["//visibility:public"],
)
test BUILD has the following structure:
cc_test(
name = "unittests",
srcs = ["scanner_test.cc"],
copts = ["-Iexternal/gtest/include"],
deps = [
"//scanner:scanner",
"#gtest//:main"
]
)
when I execute
bazel build //test:unittests
I get
INFO: Analyzed target //test:unittests (26 packages loaded, 315 targets configured).
INFO: Found 1 target...
ERROR: ../test/BUILD:1:8: Compiling test/scanner_test.cc failed: (Exit 1): gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 25 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
test/scanner_test.cc:1:10: fatal error: gtest/gtest.h: No such file or directory
1 | #include "gtest/gtest.h"
| ^~~~~~~~~~~~~~~
compilation terminated.
Target //test:unittests failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2.314s, Critical Path: 0.08s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
As the other answer mentions:
The file BUILD.gtest is not needed.
Because gtest repo / release archive already provides one.
The reason why your own didn't behave as you might have expected is you've tried to point to the headers by manipulating copts which is applied only to building that one specific cc_library target (from linked docs):
The flags take effect only for compiling this target, not its dependencies, so be careful about header files included elsewhere.
Whereas to expose these interfaces to other targets consuming it you need to use includes (docs again):
Unlike COPTS, these flags are added for this rule and every rule that depends on it.
The file BUILD.gtest is not needed.
WORKSPACE.bazel:
workspace(name = "GTestDemo")
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "gtest",
url = "https://github.com/google/googletest/archive/release-1.10.0.tar.gz",
sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",
strip_prefix = "googletest-release-1.10.0",
)
BUILD.bazel:
cc_test(
name = "tests",
srcs = ["test.cpp"],
deps = [
"#gtest//:gtest",
"#gtest//:gtest_main",
],
)
test.cpp:
#include <iostream>
#include <fstream>
#include "gtest/gtest.h"
using namespace std;
TEST(sample_test_case, sample_test) {
EXPECT_EQ(1, 1);
}
Tested with Bazel 4.1.0.

Problem using VariantDir with a SCons Builder that generates a list of files to use as source for Program

I have a SConstruct that build my tool in 3 steps:
build a static library. In my case it's the antlr4 c++ runtime
generate the antlr4 cpp and h files (listener, visitor etc) of an antlr4's grammar
finally build a program using those files and linking to the antlr4 runtime library.
1 and 2 can be built in any order, even together but 3 ahs to be built when the other two have finished.
All this works perfectly when I don't use any VariantDir, however SCons fails when I try to use a variant directory, saying that it can't find the autogenerated files:
cons: *** [build/Parser/CoralBaseListener.o] Source `build/Parser/CoralBaseListener.cpp' not found, needed by target `build/Parser/CoralBaseListener.o'.
this is the whole SConstruct:
import os
import subprocess
env = Environment(
CC = "clang",
CXX = "clang++",
CXXFLAGS = ['-std=c++11', '-stdlib=libc++']
)
env.Append(ENV = {'CLASSPATH': './dependencies/antlr4/antlr-4.8-complete.jar'})
# RelWithDbgInfo
env.Append(CXXFLAGS = ['-O2', '-g', '-DNDEBUG'])
VariantDir('./build', './src')
VariantDir('./build/antlr4Runtime', './dependencies/antlr4Runtime')
#
# Builder for generating grammar files with antlr4 (the java app)
#
def auto_antlr_generated_files(prefix):
return [File(prefix + _file + ext) for _file in [
'CoralBaseListener',
'CoralBaseVisitor',
'CoralLexer',
'CoralListener',
'CoralParser',
'CoralVisitor'] for ext in ['.cpp', '.h']
]
def antlr_emitter(target, source, env):
target = auto_antlr_generated_files('src/Parser/')
return target, source
AntlrBuilder = Builder(
action='java org.antlr.v4.Tool $SOURCE -Dlanguage=Cpp -package Coral -visitor -listener -o src/Parser',
emitter=antlr_emitter
)
env.Append(BUILDERS={'Antlr': AntlrBuilder})
#
# Cloning the Environment for Antlr4 runtime
#
antlrEnv = env.Clone()
antlrEnv.Append(CXXFLAGS = [
'-Wall',
'-pedantic',
'-W',
'-Wno-overloaded-virtual',
'-Wno-dollar-in-identifier-extension',
'-Wno-four-char-constants'
])
#
# Building in 3 steps, first the antlr4 runtime library, then the parser files with Antlr then the final program
#
AntlrRuntime = antlrEnv.StaticLibrary(
'lib/antlr4-runtime',
source =
Glob('./build/antlr4Runtime/*.cpp') + \
Glob('./build/antlr4Runtime/atn/*.cpp') + \
Glob('./build/antlr4Runtime/dfa/*.cpp') + \
Glob('./build/antlr4Runtime/misc/*.cpp') + \
Glob('./build/antlr4Runtime/support/*.cpp') + \
Glob('./build/antlr4Runtime/tree/*.cpp') + \
Glob('./build/antlr4Runtime/tree/pattern/*.cpp') + \
Glob('./build/antlr4Runtime/tree/xpath/*.cpp'),
CPPPATH = './build/antlr4Runtime',
ARFLAGS = 'qc'
)
ParserFiles = env.Antlr(source='./Coral.g4')
CoralLang = env.Program(target = 'coral',
source = Glob('./build/*.cpp') + Glob('./build/Parser/*.cpp'),
CPPPATH = ['./build', './build/antlr4Runtime'],
LIBPATH = './lib',
LIBS = ['antlr4-runtime']
)
Requires(ParserFiles, AntlrRuntime)
Depends(auto_antlr_generated_files('./build/src/Parser/'), ParserFiles)
Depends(CoralLang, ParserFiles)
It is probably worth mentioning that at this point, when I have the error, the autogenerated antlr4 files are not in ./src nor in ./build, So basically the command never generated them in first place.
note that without VariantDir everything works as expected. Everything is build in the right steps without problems
import os
import subprocess
env = Environment(
CC = "clang",
CXX = "clang++",
CXXFLAGS = ['-std=c++11', '-stdlib=libc++']
)
env.Append(ENV = {'CLASSPATH': './dependencies/antlr4/antlr-4.8-complete.jar'})
# RelWithDbgInfo
env.Append(CXXFLAGS = ['-O2', '-g', '-DNDEBUG'])
#
# Builder for generating grammar files with antlr4 (the java app)
#
def auto_antlr_generated_files(prefix):
return [File(prefix + _file + ext) for _file in [
'CoralBaseListener',
'CoralBaseVisitor',
'CoralLexer',
'CoralListener',
'CoralParser',
'CoralVisitor'] for ext in ['.cpp', '.h']
]
def antlr_emitter(target, source, env):
target = auto_antlr_generated_files('src/Parser/')
return target, source
AntlrBuilder = Builder(
action='java org.antlr.v4.Tool $SOURCE -Dlanguage=Cpp -package Coral -visitor -listener -o src/Parser',
emitter=antlr_emitter
)
env.Append(BUILDERS={'Antlr': AntlrBuilder})
#
# Cloning the Environment for Antlr4 runtime
#
antlrEnv = env.Clone()
antlrEnv.Append(CXXFLAGS = [
'-Wall',
'-pedantic',
'-W',
'-Wno-overloaded-virtual',
'-Wno-dollar-in-identifier-extension',
'-Wno-four-char-constants'
])
#
# Building in 3 steps, first the antlr4 runtime library, then the parser files with Antlr then the final program
#
AntlrRuntime = antlrEnv.StaticLibrary(
'lib/antlr4-runtime',
source =
Glob('./dependencies/antlr4Runtime/*.cpp') + \
Glob('./dependencies/antlr4Runtime/atn/*.cpp') + \
Glob('./dependencies/antlr4Runtime/dfa/*.cpp') + \
Glob('./dependencies/antlr4Runtime/misc/*.cpp') + \
Glob('./dependencies/antlr4Runtime/support/*.cpp') + \
Glob('./dependencies/antlr4Runtime/tree/*.cpp') + \
Glob('./dependencies/antlr4Runtime/tree/pattern/*.cpp') + \
Glob('./dependencies/antlr4Runtime/tree/xpath/*.cpp'),
CPPPATH = './dependencies/antlr4Runtime',
ARFLAGS = 'qc'
)
ParserFiles = env.Antlr(source='./Coral.g4')
CoralLang = env.Program(target = 'coral',
source = Glob('./src/*.cpp') + Glob('./src/Parser/*.cpp'),
CPPPATH = ['./src', './dependencies/antlr4Runtime'],
LIBPATH = './lib',
LIBS = ['antlr4-runtime']
)
Requires(ParserFiles, AntlrRuntime)
Depends(CoralLang, ParserFiles)
I have the feeling that I'm doing something remarkably silly but I can't figure out what exactly.
This is what SCons output with the first SConstruct, the one that uses VariantDir:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: *** [build/Parser/CoralBaseListener.o] Source `build/Parser/CoralBaseListener.cpp' not found, needed by target `build/Parser/CoralBaseListener.o'.
scons: building terminated because of errors.
This is really all and if I read this correctly, SCons is jumping straight to point 3 and of course at it fails because point 2 didn't create the files that point 3 needs as source.
This is instead a snippet of the output of the second SConstruct, the one that doesn't use VariantDir. (I cut off some of the similar lines where Scons create the static library, but they are all similar, as you know)
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
clang++ -o dependencies/antlr4Runtime/ANTLRErrorListener.o -c -std=c++11 -stdlib=libc++ -O2 -g -DNDEBUG -Wall -pedantic -W -Wno-overloaded-virtual -Wno-dollar-in-identifier-extension -Wno-four-char-constants -Idependencies/antlr4Runtime dependencies/antlr4Runtime/ANTLRErrorListener.cpp
...
clang++ -o dependencies/antlr4Runtime/tree/xpath/XPathWildcardElement.o -c -std=c++11 -stdlib=libc++ -O2 -g -DNDEBUG -Wall -pedantic -W -Wno-overloaded-virtual -Wno-dollar-in-identifier-extension -Wno-four-char-constants -Idependencies/antlr4Runtime dependencies/antlr4Runtime/tree/xpath/XPathWildcardElement.cpp
ar qc lib/libantlr4-runtime.a dependencies/antlr4Runtime/ANTLRErrorListener.o ... dependencies/antlr4Runtime/tree/xpath/XPathWildcardElement.o
ranlib lib/libantlr4-runtime.a
java org.antlr.v4.Tool Coral.g4 -Dlanguage=Cpp -package Coral -visitor -listener -o src/Parser
clang++ -o src/Parser/CoralListener.o -c -std=c++11 -stdlib=libc++ -O2 -g -DNDEBUG -Isrc -Idependencies/antlr4Runtime src/Parser/CoralListener.cpp
clang++ -o src/Parser/CoralBaseListener.o -c -std=c++11 -stdlib=libc++ -O2 -g -DNDEBUG -Isrc -Idependencies/antlr4Runtime src/Parser/CoralBaseListener.cpp
clang++ -o src/Parser/CoralParser.o -c -std=c++11 -stdlib=libc++ -O2 -g -DNDEBUG -Isrc -Idependencies/antlr4Runtime src/Parser/CoralParser.cpp
clang++ -o src/Parser/CoralLexer.o -c -std=c++11 -stdlib=libc++ -O2 -g -DNDEBUG -Isrc -Idependencies/antlr4Runtime src/Parser/CoralLexer.cpp
clang++ -o src/main.o -c -std=c++11 -stdlib=libc++ -O2 -g -DNDEBUG -Isrc -Idependencies/antlr4Runtime src/main.cpp
clang++ -o src/Parser/CoralVisitor.o -c -std=c++11 -stdlib=libc++ -O2 -g -DNDEBUG -Isrc -Idependencies/antlr4Runtime src/Parser/CoralVisitor.cpp
clang++ -o src/Parser/CoralBaseVisitor.o -c -std=c++11 -stdlib=libc++ -O2 -g -DNDEBUG -Isrc -Idependencies/antlr4Runtime src/Parser/CoralBaseVisitor.cpp
clang++ -o coral src/main.o src/Parser/CoralBaseListener.o src/Parser/CoralBaseVisitor.o src/Parser/CoralLexer.o src/Parser/CoralListener.o src/Parser/CoralParser.o src/Parser/CoralVisitor.o -Llib -lantlr4-runtime
scons: done building targets.
So reading this is obvious that Scons start with building the static library, then he runs antlr to generate the files needed to parse my syntax and finally, when all the dependencies are created, it build the program.

Building Poco 1.9.0 with Crypto module

I need to build Poco 1.9.0 with clang for Android armeabi-v7a.
I build it like this:
./configure --no-sharedmemory --no-wstring --config=Android-armeabi-v7a-clang --no-samples --no-tests --omit=Data,PageCompiler,ApacheConnector,CppParser,PDF,PocoDoc,ProGen,Encodings,CppUnit,MongoDB,Redis,SevenZip,Zip
make -j4
make install
Here is configuration file for Android-armeabi-v7a-clang I have created:
#
# $Id: //poco/1.4/build/config/Android#3 $
#
# Android
#
# Make settings for Android NDK
#
#
# General Settings
#
LINKMODE ?= STATIC
ANDROID_ABI ?= armeabi-v7a
POCO_TARGET_OSNAME = Android
POCO_TARGET_OSARCH = $(ANDROID_ABI)
ifeq ($(ANDROID_ABI),armeabi)
TOOL = arm-linux-androideabi
ARCHFLAGS = -mthumb
else
ifeq ($(ANDROID_ABI),armeabi-v7a)
TOOL = arm-linux-androideabi
ARCHFLAGS = -march=armv7-a -mfloat-abi=softfp
LINKFLAGS = -Wl,--fix-cortex-a8
else
ifeq ($(ANDROID_ABI),x86)
TOOL = i686-linux-android
ARCHFLAGS = -march=i686 -msse3 -mstackrealign -mfpmath=sse
else
ifeq ($(ANDROID_ABI),x86_64)
TOOL = x86_64-linux-android
ARCHFLAGS = -msse3 -mstackrealign -mfpmath=sse
else
ifeq ($(ANDROID_ABI),arm64-v8a)
TOOL = aarch64-linux-android
ARCHFLAGS = -march=armv8-a
else
$(error Invalid ABI specified in ANDROID_ABI)
endif
endif
endif
endif
endif
#
# Define Tools
#
CC = $(TOOL)-clang
CXX = $(TOOL)-clang++
LINK = $(CXX)
STRIP = $(TOOL)-strip
LIB = $(TOOL)-ar -cr
RANLIB = $(TOOL)-ranlib
SHLIB = $(CXX) -shared -Wl,-soname,$(notdir $#) -o $#
SHLIBLN = $(POCO_BASE)/build/script/shlibln
DEP = $(POCO_BASE)/build/script/makedepend.gcc
SHELL = sh
RM = rm -rf
CP = cp
MKDIR = mkdir -p
#
# Extension for Shared Libraries
#
SHAREDLIBEXT = .so.$(target_version)
SHAREDLIBLINKEXT = .so
#
# Compiler and Linker Flags
#
CFLAGS = $(ARCHFLAGS) -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing
CFLAGS32 =
CFLAGS64 =
CXXFLAGS = $(ARCHFLAGS) -std=c++11 -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -frtti -fexceptions
CXXFLAGS32 =
CXXFLAGS64 =
LINKFLAGS +=
LINKFLAGS32 =
LINKFLAGS64 =
STATICOPT_CC =
STATICOPT_CXX =
STATICOPT_LINK = -static
SHAREDOPT_CC =
SHAREDOPT_CXX =
SHAREDOPT_LINK = -Wl,-rpath,$(LIBPATH)
DEBUGOPT_CC = -g -D_DEBUG
DEBUGOPT_CXX = -g -D_DEBUG
DEBUGOPT_LINK = -g
RELEASEOPT_CC = -O3 -DNDEBUG -fomit-frame-pointer
RELEASEOPT_CXX = -O2 -DNDEBUG -fomit-frame-pointer
RELEASEOPT_LINK = -O2
#
# System Specific Flags
#
SYSFLAGS = -DPOCO_ANDROID -DPOCO_NO_FPENVIRONMENT -DPOCO_NO_WSTRING -DPOCO_NO_SHAREDMEMORY
#
# System Specific Libraries
#
SYSLIBS = -lstdc++ -lsupc++
When I try to build it I get multiple occurrences of this error:
In file included from src/OpenSSLInitializer.cpp:15:
In file included from include/Poco/Crypto/OpenSSLInitializer.h:21:
include/Poco/Crypto/Crypto.h:30:10: fatal error: 'openssl/opensslv.h' file not found
#include <openssl/opensslv.h>
^
1 error generated.
...
In file included from src/X509Certificate.cpp:15:
In file included from include/Poco/Crypto/X509Certificate.h:21:
include/Poco/Crypto/Crypto.h:30:10: fatal error: 'openssl/opensslv.h' file not found
#include <openssl/opensslv.h>
^
1 error generated.
...
As I said earlier I use poco version 1.9.0, clang version 3.8.0 on linux machine. Build without Crypto modul works fine.
Thanks for help
Solve by adding statically builded openssl library to configuration of poco
./configure --no-sharedmemory --no-wstring --config=Android-armeabi-v7a-clang --no-samples --no-tests --include-path=./openssl/Android/armeabi-v7a/include/--omit=Data,PageCompiler,ApacheConnector,CppParser,PDF,PocoDoc,ProGen,Encodings,CppUnit,MongoDB,Redis,SevenZip,Zip

No type named 'VarDictionary' in namespace 'pp' using PNaCl

Can someone explain me why am I getting the compile error
error: no type named 'VarDictionary' in namespace 'pp'
pp::VarDictionary dictionary;
~~~~^
I'm tying to set a dictionary in the function
virtual void HandleMessage(const pp::Var& message) {
}
I copied the example from the bottom of this Google page https://developer.chrome.com/native-client/devguide/coding/message-system
and tried something simple like this
virtual void HandleMessage(const pp::Var& message) {
pp::VarDictionary dictionary;
pp::VarArray an_array;
an_array.Set(0, pp::Var("string0"));
an_array.Set(1, pp::Var("string1"));
dictionary.Set(pp::Var("param_array"), an_array);
PostMessage(dictionary);
}
but when I compile the code i get the error message for the pp::VarDictionary dictionary; however no problem with the pp::VarArray an_array;
I'm using this Makefile from Google
# Copyright (c) 2013 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# GNU Make based build file.  For details on GNU Make see:
# http://www.gnu.org/software/make/manual/make.html
#
#
# Get pepper directory for toolchain and includes.
#
# If NACL_SDK_ROOT is not set, then assume it can be found three directories up.
#
THIS_MAKEFILE := $(abspath $(lastword $(MAKEFILE_LIST)))
NACL_SDK_ROOT ?= $(abspath $(dir $(THIS_MAKEFILE))../..)
# Project Build flags
WARNINGS := -Wno-long-long -Wall -Wswitch-enum -pedantic -Werror
CXXFLAGS := -pthread -std=gnu++98 $(WARNINGS)
#
# Compute tool paths
#
GETOS := python $(NACL_SDK_ROOT)/tools/getos.py
OSHELPERS = python $(NACL_SDK_ROOT)/tools/oshelpers.py
OSNAME := $(shell $(GETOS))
RM := $(OSHELPERS) rm
PNACL_TC_PATH := $(abspath $(NACL_SDK_ROOT)/toolchain/$(OSNAME)_pnacl)
PNACL_CXX := $(PNACL_TC_PATH)/bin/pnacl-clang++
PNACL_FINALIZE := $(PNACL_TC_PATH)/bin/pnacl-finalize
CXXFLAGS := -I$(NACL_SDK_ROOT)/include
LDFLAGS := -L$(NACL_SDK_ROOT)/lib/pnacl/Release -lppapi_cpp -lppapi -ljsoncpp
#
# Disable DOS PATH warning when using Cygwin based tools Windows
#
CYGWIN ?= nodosfilewarning
export CYGWIN
# Declare the ALL target first, to make the 'all' target the default build
all: job1.pexe
clean:
$(RM) job1.pexe job1.bc
job1.bc: job1.cc
$(PNACL_CXX) -o $# $< -O2 $(CXXFLAGS) $(LDFLAGS)
job1.pexe: job1.bc
$(PNACL_FINALIZE) -o $# $<
#
# Makefile target to run the SDK's simple HTTP server and serve this example.
#
HTTPD_PY := python $(NACL_SDK_ROOT)/tools/httpd.py
.PHONY: serve
serve: all
$(HTTPD_PY) -C $(CURDIR)
You need to add the header file for var_dictionary.h that is where the class you are trying to access is declared.
Source code for that header is available here

Compile and link sources from different directories with make and gcc

I`m having a Project with some subdirectories. I want to compile them with one makefile per Directory and link all Output files into one executable. Can anyone explain me, which commands I should use (-c or -g or extra call)?
makefile in my root-directory:
LIBS =
# The test will be called in this file. There is no need to change this.
#SRCS = main_test.c
SRCS = min.c max.c
###############################################################################
# #
# Normally it is not needed to edited below this. #
# #
###############################################################################
#SRCS = main_test.c Automated.c Basic.c Console.c CUCurses.c CUError.c Cunit_intl.c \
# MyMem.c TestDB.c TestRun.c Util.c wxWidget.c main_test.c \
# $(TST_SRCS)
# define the C object files
#
# This uses Suffix Replacement within a macro:
# $(name:string1=string2)
# For each word in 'name' replace 'string1' with 'string2'
OBJ = $(SRCS:%.c=%.o)
# define the C compiler to use
CC = gcc
# define any compile-time flags
ODIR = out
#compile and link
#CFLAGS = -O0 -g -Wall -fmessage-length=0 -fprofile-arcs -ftest-coverage
#compile without link
CFLAGS = -O0 -c -Wall -fmessage-length=0 -fprofile-arcs -ftest-coverage
#TODO Linkerflags
LFLAGS = --coverage
#VPATH=test
#VPATH=source
# define the executable file,
TARGET = CUnit
export COVERAGE = $(TST_SRCS)
export STUBS = $(STUB_SRCS)
all:
$(MAKE) -C stub
$(MAKE) -C source
#echo --- build finished ---
#echo.
#echo TODO
#echo --- start linking ---
#echo.
and makefile of subdirectory
# define any directories containing header files other than /usr/include
# TODO
# define any libraries to link into executable:
# if I want to link in libraries (libx.so or libx.a) I use the -llibname
# option, something like (this will link in libmylib.so and libm.so:
LIBS =
# TODO define the C source files
SRCS = $(COVERAGE)
# define the C object files
#
# This uses Suffix Replacement within a macro:
# $(name:string1=string2)
# For each word in 'name' replace 'string1' with 'string2'
OBJ = $(SRCS:%.c=%.o)
# define the C compiler to use
CC = gcc
# define any compile-time flags
ODIR = ../out
#compile without link
CFLAGS = -O0 -c -fmessage-length=0 -fprofile-arcs -ftest-coverage
#TODO Linkerflags
LFLAGS = --coverage
# define the executable file,
all: $(TARGET) $(OBJ)
$(CC) $(OBJ) $(CFLAGS) -o $(TARGET) $(LFLAGS) $(OBJ)
#echo +++ build of source finished +++
clean:
$(RM) *.o *~ $(MAIN)
# DO NOT DELETE THIS LINE -- make depend needs it
I it is easier for the linker, if all Output file are in the same Directory. Works this with ODIR?
With the compiler option -c -g I can compile each submake and link the object files together.
CFLAGS = -O0 -Wall -c -g -fmessage-length=0 -fprofile-arcs -ftest-coverage