Problem when I try to inlclude functional lib

391 views
Skip to first unread message

Gabriel Santos

unread,
Apr 7, 2020, 9:55:47 AM4/7/20
to cpputest
Hello,

I'm trying to use the funcitional library, however the compilation fails using CppUtest with "MakefileWorker.mk". But using my own makefile and arm-none-eabi it compiles. I also tried using eclipse enviroment (eclipse generates its custom makefile) and worked as well. Actually I'm trying to compile only one file, just the Alltests.cpp. If I comment out the #include <functional>, it works.

My termianl output follows:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CppUTest ok
CppUTest is configured. Ready to run 'test'
compiling AllTests.cpp
In file included from /usr/include/c++/8/functional:59,
                 from /home/gabriel/Projects/dt-07-fw-cacau_tiva/test/AllTests.cpp:18:
/usr/include/c++/8/bits/std_function.h: In static member function ‘static void std::_Function_base::_Base_manager<_Functor>::_M_clone(std::_Any_data&, const std::_Any_data&, std::true_type)’:
/usr/include/c++/8/bits/std_function.h:164:11: error: ‘__dest’ does not name a type
    ::new (__dest._M_access()) _Functor(__source._M_access<_Functor>());
           ^~~~~~
/usr/include/c++/8/bits/std_function.h:164:17: error: expected ‘)’ before ‘.’ token
    ::new (__dest._M_access()) _Functor(__source._M_access<_Functor>());
          ~      ^
                 )
/usr/include/c++/8/bits/std_function.h: In static member function ‘static void std::_Function_base::_Base_manager<_Functor>::_M_init_functor(std::_Any_data&, _Functor&&, std::true_type)’:
/usr/include/c++/8/bits/std_function.h:245:11: error: ‘__functor’ does not name a type
  { ::new (__functor._M_access()) _Functor(std::move(__f)); }
           ^~~~~~~~~
/usr/include/c++/8/bits/std_function.h:245:20: error: expected ‘)’ before ‘.’ token
  { ::new (__functor._M_access()) _Functor(std::move(__f)); }
          ~         ^
                    )
Building archive /home/gabriel/Projects/dt-07-fw-cacau_tiva/test/output/libdt-07-fw-cacau_tiva.a
Linking dt-07-fw-cacau_tiva_tests
g++: error: /home/gabriel/Projects/dt-07-fw-cacau_tiva/test/output//home/gabriel/Projects/dt-07-fw-cacau_tiva/test/AllTests.o: No such file or directory
Running dt-07-fw-cacau_tiva_tests
/bin/sh: ./dt-07-fw-cacau_tiva_tests: No such file or directory
Tests done
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

My AllTests.cpp
/**
 * Includes
 */
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTestExt/MockSupportPlugin.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include <functional>

/**
 * Local Functions
 */
int main(int ac, const char** av)
{
    MockSupportPlugin mockPlugin;

    TestRegistry::getCurrentRegistry()->installPlugin(&mockPlugin);
    int result = RUN_ALL_TESTS(ac, av);

    return result;
}

My file to call MakefileWorker.mk:

# Parameters
COMPONENT_NAME= $(notdir $(shell pwd))# Project Name
PROJECT_PATH= $(shell pwd)# Project Path
CPPUTEST_HOME=${HOME}/cpputest

CPPUTEST_WARNINGFLAGS += -Wall 
CPPUTEST_WARNINGFLAGS += -fmessage-length=0

# Set this to @ to keep the makefile quiet
# SILENCE = @echo
SILENCE = @ 

#---- Outputs ----#
TARGET_LIB = $(PROJECT_PATH)/test/output/lib$(COMPONENT_NAME).a
TEST_TARGET = $(COMPONENT_NAME)_tests

#--- Inputs ----#
PROJECT_HOME_DIR = .
CPP_PLATFORM = Gcc

CPPUTEST_OBJS_DIR = $(PROJECT_PATH)/test/output
CPPUTEST_LIB_DIR = $(PROJECT_PATH)/test/output

CPPUTEST_EXE_FLAGS = -v -c

INCLUDE_DIRS = $(CPPUTEST_HOME)/include \


TEST_SRC_DIRS += $(PROJECT_PATH)/test 

CPPUTEST_USE_EXTENSIONS = Y

include $(CPPUTEST_HOME)/build/MakefileWorker.mk





James Grenning

unread,
Apr 7, 2020, 9:26:50 PM4/7/20
to cpputest

Hi

I think you probably have a conflict with the new macros, like the STL problem mentioned in this section

https://cpputest.github.io/manual.html#advanced

HTH, James

James Grenning - Author of TDD for Embedded C - wingman-sw.com/tddec
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw
wingman software

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cpputest/26af7094-084a-4e8e-bd6c-7b1c216cb37f%40googlegroups.com.

Gabriel Santos

unread,
Apr 8, 2020, 9:53:59 AM4/8/20
to cpputest
Hello James,

Thanks to answer. As you suggested I read again the documentation and I created a new file that include some STD libraries before MemoryLeakDetectorNewMacros.h. 

It's compiling!

Thanks again.
To unsubscribe from this group and stop receiving emails from it, send an email to cppu...@googlegroups.com.

Hugo Quiroz

unread,
Dec 5, 2024, 3:55:48 AM12/5/24
to cpputest
Hello,

I am having a similar issue also and have tried most of the solutions listed in https://cpputest.github.io/manual.html#advanced. Trying on my personal project but even on the starter project I am seeing the same issue, https://github.com/jwgrenning/cpputest-starter-project. I tried with Cygwin clean build and MSYS/Mingw64 clean build, both result in same issue. tried configuring with --disable-memory-leak-detection. not sure what else to do, will try on ubuntu later but need this to work on windows.

----------------------------------------------------------------

CppUTest Version 4.0

Current compiler options:
   CC:                                  gcc
   CXX:                                 g++
   CC version:                          12.4.0
   CXX version:
   LD:                                  /usr/x86_64-pc-cygwin/bin/ld.exe
   Default CFLAGS:                      -g -O2
   Default CXXFLAGS:                    -g -O2
   CppUTest CFLAGS:                       -Wno-c++11-long-long -Wno-long-long -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -pedantic -Wsign-conversion -Wstrict-prototypes -Wno-disabled-macro-expansion -Wno-padded
   CppUTest CXXFLAGS:                     -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-c++14-compat -Wno-c++11-long-long -Wno-long-long -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -pedantic -Wsign-conversion -Woverloaded-virtual -Wno-disabled-macro-expansion -Wno-padded -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables -Wno-old-style-cast
   CppUTest CPPFLAGS:                    -I ./include
   CppUTest LDFLAGS:
   CppUTest LIB:                           -lpthread

Features configured in CppUTest:
   C++ standard used:                   default
   Memory Leak Detection:               no
   Compiling extensions:                yes
   Use Long Long (if available):        yes
   Disable CppUTest compile/link flags: yes
   Address sanitizer:                   no

   Using Standard C++ Library:          yes
   Using Standard C Library:            yes

   Generating map file:                 no
   Compiling w coverage info:           no

----------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/* cygwin console*/

$ make all
compiling AllTests.cpp
In file included from /usr/lib/gcc/x86_64-pc-cygwin/12/include/c++/map:60,
                 from tests/AllTests.cpp:1:
/usr/lib/gcc/x86_64-pc-cygwin/12/include/c++/bits/stl_tree.h: In member function ‘void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_construct_node(_Link_type, _Args&& ...)’:
/usr/lib/gcc/x86_64-pc-cygwin/12/include/c++/bits/stl_tree.h:596:21: error: ‘__node’ does not name a type; did you mean ‘__not_’?
  596 |               ::new(__node) _Rb_tree_node<_Val>;
      |                     ^~~~~~
      |                     __not_
compilation terminated due to -Wfatal-errors.
make: *** [/cygdrive/c/repos/cpputest/build/MakefileWorker.mk:553: test-obj/tests/AllTests.o] Error 1

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/* All Tests.cpp*/

#include <map>
#include "CppUTest/CommandLineTestRunner.h"

int main(int ac, char** av)
{
    MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
    return CommandLineTestRunner::RunAllTests(ac, av);
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/* Makefile*/

#Set this to @ to keep the makefile quiet

SILENCE = @

#---- Outputs ----#
COMPONENT_NAME = your


#--- Inputs ----#
PROJECT_HOME_DIR = .
ifeq "$(CPPUTEST_HOME)" ""
$(error The environment variable CPPUTEST_HOME is not set. \
Set it to where cpputest is installed)
endif

# --- SRC_FILES and SRC_DIRS ---
# Production code files are compiled and put into
# a library to link with the test runner.
#
# Test code of the same name overrides
# production code at link time.
#
# SRC_FILES specifies individual production
# code files.
#
# SRC_DIRS specifies directories containing
# production code C and CPP files.
#
SRC_FILES += example-src/Example.c
SRC_DIRS += example-platform

# --- TEST_SRC_FILES and TEST_SRC_DIRS ---
# Test files are always included in the build.
# Production code is pulled into the build unless
# it is overriden by code of the same name in the
# test code.
#
# TEST_SRC_FILES specifies individual test files to build.
# TEST_SRC_DIRS, builds everything in the directory

TEST_SRC_FILES +=
TEST_SRC_DIRS += tests
TEST_SRC_DIRS += tests/io-cppumock
TEST_SRC_DIRS += tests/printf-spy

# tests/example-fff \
# tests/fff \

# --- MOCKS_SRC_DIRS ---
# MOCKS_SRC_DIRS specifies a directories where you can put your
# mocks, stubs and fakes.  You can also just put them
# in TEST_SRC_DIRS
MOCKS_SRC_DIRS +=

# Turn on CppUMock
CPPUTEST_USE_EXTENSIONS = Y

# INCLUDE_DIRS are searched in order after the included file's
# containing directory
INCLUDE_DIRS += $(CPPUTEST_HOME)/include
INCLUDE_DIRS += $(CPPUTEST_HOME)/include/Platforms/Gcc
INCLUDE_DIRS += example-include
INCLUDE_DIRS += example-fff
INCLUDE_DIRS += tests/exploding-fakes
INCLUDE_DIRS += tests/fff


# --- CPPUTEST_OBJS_DIR ---
# CPPUTEST_OBJS_DIR lets you control where the
# build artifact (.o and .d) files are stored.
#
# If you have to use "../" to get to your source path
# the makefile will put the .o and .d files in surprising
# places.
#
# To make up for each level of "../"in the source path,
# add place holder subdirectories to CPPUTEST_OBJS_DIR
# each.
# e.g. if you have "../../src", set to "test-objs/1/2"
#
# This is kind of a kludge, but it causes the
# .o and .d files to be put under objs.
CPPUTEST_OBJS_DIR = test-obj

CPPUTEST_LIB_DIR = test-lib

# You may have to tweak these compiler flags
#    CPPUTEST_WARNINGFLAGS - apply to C and C++
#    CPPUTEST_CFLAGS - apply to C files only
#    CPPUTEST_CXXFLAGS - apply to C++ files only
#    CPPUTEST_CPPFLAGS - apply to C and C++ Pre-Processor
#
# If you get an error like this
#     TestPlugin.h:93:59: error: 'override' keyword is incompatible
#        with C++98 [-Werror,-Wc++98-compat] ...
# The compiler is basically telling you how to fix the
# build problem.  You would add this flag setting
#     CPPUTEST_CXXFLAGS += -Wno-c++14-compat




# Some flags to quiet clang
ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang"), 1)
CPPUTEST_WARNINGFLAGS += -Wno-unknown-warning-option
CPPUTEST_WARNINGFLAGS += -Wno-covered-switch-default
CPPUTEST_WARNINGFLAGS += -Wno-reserved-id-macro
CPPUTEST_WARNINGFLAGS += -Wno-keyword-macro
CPPUTEST_WARNINGFLAGS += -Wno-documentation
CPPUTEST_WARNINGFLAGS += -Wno-missing-noreturn
endif

CPPUTEST_WARNINGFLAGS += -Wall
CPPUTEST_WARNINGFLAGS += -Werror
CPPUTEST_WARNINGFLAGS += -Wfatal-errors
CPPUTEST_WARNINGFLAGS += -Wswitch-default
CPPUTEST_WARNINGFLAGS += -Wno-format-nonliteral
CPPUTEST_WARNINGFLAGS += -Wno-sign-conversion
CPPUTEST_WARNINGFLAGS += -Wno-pedantic
CPPUTEST_WARNINGFLAGS += -Wno-shadow
CPPUTEST_WARNINGFLAGS += -Wno-missing-field-initializers
CPPUTEST_WARNINGFLAGS += -Wno-unused-parameter
CPPUTEST_CFLAGS += -pedantic
CPPUTEST_CFLAGS += -Wno-missing-prototypes
CPPUTEST_CFLAGS += -Wno-strict-prototypes
CPPUTEST_CXXFLAGS += -Wno-c++14-compat
CPPUTEST_CXXFLAGS += --std=c++11
CPPUTEST_CXXFLAGS += -Wno-c++98-compat-pedantic
CPPUTEST_CXXFLAGS += -Wno-c++98-compat

# Coloroze output
CPPUTEST_EXE_FLAGS += -c

# --- LD_LIBRARIES -- Additional needed libraries can be added here.
# commented out example specifies math library
#LD_LIBRARIES += -lm

# Look at $(CPPUTEST_HOME)/build/MakefileWorker.mk for more controls

include $(CPPUTEST_HOME)/build/MakefileWorker.mk

Bas Vodde

unread,
Dec 5, 2024, 5:00:18 AM12/5/24
to CppUTest

Hi Hugo,

That is weird.

To ensure it is or isn’t the memory leak overload acting weird, could you add this one line before the map include:

#undef new

And see what it does.

Thanks!

Bas


To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.

Hugo Quiroz

unread,
Dec 5, 2024, 8:21:06 PM12/5/24
to cpputest
works when i #undef, also i tried on ubuntu and got same error without the #undef fix

Bas Vodde

unread,
Dec 6, 2024, 5:37:19 AM12/6/24
to CppUTest

Hi Hugo,

Strange. Then it seems the MakefileWorker somehow still adds the -include to the compile options. It is an option that automatically attaches a file as first include.
That is the place where there is a #define new what is causing this error in the Standard C++ library.

Perhaps add verbose to the make to double check that is the case. If it is, we’ll need to check in the MakefileWorker why that is the case.

Thanks,

Bas


Reply all
Reply to author
Forward
0 new messages