CppuTest to build with C++11 versions - c++11

Installed g++ 4.9.0 (experimental) version under Ubuntu (I am using certain features provided by this version)
When building my code, I use cmake from a script, and it builds correctly. gcc below contains the path where g++ is installed (/mnt...)
$_cmake_ $_dir_ -DCMAKE_CXX_COMPILER=${_gpp_} -DCMAKE_C_COMPILER=${_gcc_} -DCMAKE_BUILD_TYPE=${_build_} -DCMAKE_INSTALL_PREFIX=${_install_} -DBUILD_TESTING:BOOL=1
Now, when I make the CppuTest to build the Unit Tests for my code, I get the following error.
make all
compiling UncrosserTest.cpp
In file included from /home/miguel/Desktop/Ugur/scmProject/scm/dist/dev/mfx_prod/scm/20160207/include/scm/services/primitives.hpp:4:0,
from /home/miguel/Desktop/Ugur/scmProject/log/lidya/src/cpp/scm/services/examples/dummy_strategy/Inside.hpp:6,
from AllTests/Uncrosser/UncrosserTest.cpp:7:
/usr/include/c++/4.9/experimental/optional: In member function ‘void std::experimental::_Optional_base<_Tp, _ShouldProvideDestructor>::_M_construct(_Args&& ...)’:
/usr/include/c++/4.9/experimental/optional:294:18: error: expected type-specifier
::new (std::__addressof(this->_M_payload))
^
/usr/include/c++/4.9/experimental/optional:294:18: error: expected ‘)’
/usr/include/c++/4.9/experimental/optional: In member function ‘void std::experimental::_Optional_base<_Tp, false>::_M_construct(_Args&& ...)’:
/usr/include/c++/4.9/experimental/optional:424:18: error: expected type-specifier
::new (std::__addressof(this->_M_payload))
^
/usr/include/c++/4.9/experimental/optional:424:18: error: expected ‘)’
make: *** [objs/AllTests/Uncrosser/UncrosserTest.o] Error 1
In the CppuTest makefile have included CPPUTEST_CPPFLAGS += -std=c++1y. I guess that am missing some flags in this makefile because as I said the C++ experimental library is building correctly in my "regular" code. What am I missing ?

Possible it's an include problem, see CppUTest Manual - section Conflicts with operator new macros (STL!) and Conflicts with my own overload!
TL;DR
In UncrosserTest add includes for CppUTest after your's.
Instead of
#include <CppUTest/TestHarnes.h>
#include "whatever.h"
do
#include "whatever.h"
#include <CppUTest/TestHarnes.h>

Related

Installing gosu on FreeBSD

I'm trying to install this Ruby gem on FreeBSD, and it's failing with the following error:
# gem install gosu
Building native extensions. This could take a while...
ERROR: Error installing gosu:
ERROR: Failed to build gem native extension.
current directory: /usr/local/lib/ruby/gems/2.4/gems/gosu-0.14.5/ext/gosu
/usr/local/bin/ruby24 -I /usr/local/lib/ruby/site_ruby/2.4 -r ./siteconf20190322-6847-x8s25j.rb extconf.rb
The Gosu gem requires some libraries to be installed system-wide.
See the following site for a list:
https://github.com/gosu/gosu/wiki/Getting-Started-on-Linux
cat: /proc/cpuinfo: No such file or directory
checking for -lopenal... yes
checking for AL/al.h... yes
creating Makefile
current directory: /usr/local/lib/ruby/gems/2.4/gems/gosu-0.14.5/ext/gosu
make "DESTDIR=" clean
current directory: /usr/local/lib/ruby/gems/2.4/gems/gosu-0.14.5/ext/gosu
make "DESTDIR="
compiling ../../src/Audio.cpp
In file included from ../../src/Audio.cpp:17:
../../src/SndFile.hpp:111:33: warning: field 'buffer' is uninitialized when used here [-Wuninitialized]
: file(nullptr), reader(buffer.front_reader())
^
../../src/SndFile.hpp:123:33: warning: field 'buffer' is uninitialized when used here [-Wuninitialized]
: file(nullptr), reader(buffer.front_reader())
^
2 warnings generated.
compiling ../../src/AudioImpl.cpp
compiling ../../src/Bitmap.cpp
compiling ../../src/BitmapIO.cpp
compiling ../../src/BlockAllocator.cpp
compiling ../../src/Channel.cpp
compiling ../../src/Color.cpp
compiling ../../src/DirectoriesApple.cpp
compiling ../../src/DirectoriesUnix.cpp
compiling ../../src/DirectoriesWin.cpp
compiling ../../src/FileUnix.cpp
../../src/FileUnix.cpp:53:47: error: use of undeclared identifier 'S_IRUSR'
pimpl->fd = open(filename.c_str(), flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
^
../../src/FileUnix.cpp:53:55: error: use of undeclared identifier 'S_IWUSR'
pimpl->fd = open(filename.c_str(), flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
^
../../src/FileUnix.cpp:53:63: error: use of undeclared identifier 'S_IRGRP'
pimpl->fd = open(filename.c_str(), flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
^
../../src/FileUnix.cpp:53:71: error: use of undeclared identifier 'S_IWGRP'
pimpl->fd = open(filename.c_str(), flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
^
../../src/FileUnix.cpp:53:79: error: use of undeclared identifier 'S_IROTH'
pimpl->fd = open(filename.c_str(), flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
^
../../src/FileUnix.cpp:53:87: error: use of undeclared identifier 'S_IWOTH'
pimpl->fd = open(filename.c_str(), flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
^
6 errors generated.
*** Error code 1
Stop.
make: stopped in /usr/local/lib/ruby/gems/2.4/gems/gosu-0.14.5/ext/gosu
Other things I tried:
Switching compilers - from clang and c++ to g++ and gcc.
Cloning the repository and building "manually" - got the same errors.
Is it even possible to install it on FreeBSD? Searches didn't return anything useful.
On FreeBSD system headers are organized slightly differently than in Linux.
Quick man lookup reveals, that you need to
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
to make these definitions visible.

"unknown conversion type character 'l' in format" warning. Specifically when using MinGW Makefiles generated by cmake for Assimp

I've been trying unsuccessfully for a week to get a build of Assimp that is linkable with a project I'm compiling with MinGW.
It seems that the makefiles that cmake generates to build Assimp 4.1.0 are flawed somehow because when I try to use them I get some warnings which ultimately lead to a failure when trying to link "libassimp.dll"
CMakeFiles\assimp.dir/objects.a(Exporter.cpp.obj):Exporter.cpp:(.text+0x1571): undefined reference to `Assimp::ExportScene3MF(char const*, Assimp::IOSystem*, aiScene const*, Assimp::ExportProperties const*)'
collect2.exe: error: ld returned 1 exit status
code\CMakeFiles\assimp.dir\build.make:3159: recipe for target 'code/libassimp.dll' failed
mingw32-make[2]: *** [code/libassimp.dll] Error 1
CMakeFiles\Makefile2:289: recipe for target 'code/CMakeFiles/assimp.dir/all' failed
mingw32-make[1]: *** [code/CMakeFiles/assimp.dir/all] Error 2
Makefile:131: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
Before it gets to this the only error it seems is a format error in certain header files which use the %llu conversion type when referencing the ai_snprintf function.
warning: unknown conversion type character 'l' in format [-Wformat=]
warning: too many arguments for format [-Wformat-extra-args]
I'm using the latest MinGW which has g++ version 6.3.0, by default using the c++14 standard. I did a test to see if this standard on windows didn't support %llu but when I wrote a CMakeLists.txt file, generated a makefile, and compiled using the makefile, it gave no errors and ran as expected.
I've tried using cmake to generate a Visual Studio 2017 project and building it there and it links fine when used in Visual Studio. If I call the same functions and compile with MinGW it doesn't link, I guess this is just an interoperability problem, but it suggests I have everything assimp needs to be built properly.
My thoughts are, somehow assimp's cmake modules are defining what standard assimp should be compiled with, and that standard doesn't support %llu, but that sounds silly. I don't like to assume something is a bug but these warnings don't seem like they're thrown because I forgot to do something.
I've tried editing the makefile it gives me and adding to the front:
CXX = g++
CXXFLAGS = -Wall -std=c++11 $(DEBUG)
Cause somewhere it said that could work, but it didn't change anything.
I also tried defining the macro __USE_MINGW_ANSI_STDIO 1 for cmake but that didn't do anything either.
But I really don't know much about building binaries (though I've learned more than I expected to recently), so any advice, information, guidance is appreciated.

error: ‘deprecated’ was not declared in this scope

I updated my program to --std=c++11 and now I get:
g++ --std=c++11 -c eqc.cpp
In file included from eqc.cpp:16:0:
eqc.h:372:80: error: ‘deprecated’ was not declared in this scope
eqc.h:372:92: error: expected ‘)’ before ‘;’ token
eqc.h:372:92: error: expected ‘)’ before ‘;’ token
In file included from eqc.cpp:16:0:
eqc.h:372:74: error: expected unqualified-id before ‘)’ token
equation &operator[](const std::string &label) __attribute__((deprecated));
If I use the new way of specifying attributes, it's the same:
In file included from eqc.cpp:16:0:
eqc.h:371:67: error: ‘deprecated’ was not declared in this scope
eqc.h:371:79: error: expected ‘]’ before ‘;’ token
In file included from eqc.cpp:16:0:
eqc.h:371:61: error: expected unqualified-id before ‘]’ token
equation &operator[](const std::string &label) [[deprecated]];
Since I can't find anything on the web about this error, I must be making some silly mistake. But which?
The system is Ubuntu 16.04 and the compiler:
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
The problem was a library (libginac6 1.7.0) that said
#define deprecated attribute ((deprecated));
After updating the library (to version >= 1.7.1) the error disappeared since the library now says
#define attribute_deprecated attribute ((deprecated));

Some C++11 features missing when using Code Blocks 13.12, MinGW 4.8.1 and SFML 2.1

Turning to Stack Overflow after exhausting all my efforts.
I'm running Code Blocks 13.12 and MinGW 4.8.1 on a Windows 7 OS 64bit system. I spent two days trying to get the compiler to link (statically) to the SFML 2.1 library. I followed both the SFML tutorial and this video tutorial- reinstalling both Code Blocks and MinGW twice before it finally linked.
After that I was relieved that SFML was recognized, but I got 50 errors when I tried to build and run that suggested C++11 features weren't.
Added -std=gnu++11 to compiler options and 13 of those errors went away.
The remaining errors all fall into two categories: mutex is not a member of std and from time t is not a member of chrono::_V2::steady clock. I'm not even sure what _V2 is.
What am I missing?
-------------- Build: Release in PumpTracker2.0 (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -std=gnu++11 -DSFML_STATIC -O2 -std=gnu++11 -IC:\SFML-2.1\include -IC:\SFML-2.1\include -c C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp -o obj\Release\main.o
In file included from C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:25:0:
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\Account.h:37:1: error: 'mutex' in namespace 'std' does not name a type
std::mutex mu;
^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\Account.h:86:22: error: 'to_time_t' is not a member of 'std::chrono::_V2::steady_clock'
time_t currentTp = std::chrono::steady_clock::to_time_t(newly);
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\Account.h:94:48: error: 'from_time_t' is not a member of 'std::chrono::_V2::steady_clock'
std::chrono::steady_clock::time_point tNew = std::chrono::steady_clock::from_time_t(currentTp);
^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:51:2: error: 'mutex' is not a member of 'std'
std::mutex mu3;
^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:51:13: error: expected ';' before 'mu3'
std::mutex mu3;
^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:52:19: error: 'mutex' was not declared in this scope
std::unique_lock<mutex> locker3(mu3, std::defer_lock);
^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:52:24: error: template argument 1 is invalid
std::unique_lock<mutex> locker3(mu3, std::defer_lock);
^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:52:33: error: invalid type in declaration before '(' token
std::unique_lock<mutex> locker3(mu3, std::defer_lock);
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:214:22: error: 'to_time_t' is not a member of 'std::chrono::_V2::steady_clock'
pS->tpNewest = std::chrono::steady_clock::to_time_t(NextPump);
^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:245:51: error: 'from_time_t' is not a member of 'std::chrono::_V2::steady_clock'
std::chrono::steady_clock::time_point TT2 = std::chrono::steady_clock::from_time_t(pS->tpNewest);
^
Process terminated with status 1 (0 minute(s), 4 second(s))
37 error(s), 47 warning(s) (0 minute(s), 4 second(s))
As already mentioned the original MinGW distribution is not the best one to go with, if you want to go with up-to-date features. Instead there are projects like Nuwen (Stephan T. Lavavej's website) as well as MinGW Builds that provide MinGW-w64 binaries.
The mentioning of SFML is misleading, since the problems have nothing to do with SFML at all. Keep in mind however that you'll have to rebuild SFML if you change the compiler!
As a next step, it would've been important to post a minimal example of the source code that reproduces the errors, because right now, we can only guess what's going wrong, based on the errors.
If you don't use the GNU extensions explicitly, you should use -std=c++11 instead of -std=gnu++11 and if you look at the build command, you'll notice that it's included twice, which is not necessary.
And now to some guessing about the errors:
Account.h - Make sure the <mutex> header is included.
main.cpp - Make sure the <mutex> header is included.
main.cpp - If std::unique_lock<mutex> is from your code, then you need to add std::, i.e. std::unique_lock<std::mutex>.
main.cpp - time_t things seem to be resolved, but make sure anyways to include <chrono> and <ctime> (since time_t is defined in <ctime>).

Compiling SUNDANCE 4.73 with gcc 4.5.2 on Ubuntu 64 bit

This might sound something very basic/naive.. but its been ages since I have been with C/C++ and feel lost with this..
I am busy getting started with opinionfinder, which requires me to get SUNDANCE 4.3.7. Getting to compile SUNDANCE is proving to be a bigger effort than i thought.
Following instructions, I launch the install_sundace script, but get this error... Looks like my compiling environment is not properly detected...
Few things I already tried-
the install_sundance script uses c-shell. As a test, In installed C shell and tried to see if I can still get my C compilation environment fine. That works fine.
I tried writing a basic program which uses at least one library other than stdio, and it works (I tried Strings.h)
The error message that I am getting -
Command being run -
g++ -Wall -Wno-deprecated -pipe -g -static -I../include -DHOME=\"/media/misc/development/opinionfinder/software/sundance-4.37/\" -c -fPIC -o shared/activation.o activation.C
And the error message -
In file included from nlptypes.h:16:0,
from activation.h:46,
from activation.C:26:
../include/sunstr.h: In constructor ‘sunstr::SRef::SRef(const char*)’:
../include/sunstr.h:99:21: error: ‘strlen’ was not declared in this scope
../include/sunstr.h:102:20: error: ‘strcpy’ was not declared in this scope
../include/sunstr.h: In member function ‘void sunstr::SRef::Assign(const char*)’:
../include/sunstr.h:131:26: error: ‘strlen’ was not declared in this scope
../include/sunstr.h:136:19: error: ‘strcpy’ was not declared in this scope
Superficially, there appears to be a missing #include <string.h> or #include <cstring> in the sunstr.h header.
With <cstring>, you'd need some using clauses too - one for each of the two functions.
You do not add a using namespace std; clause to a header.

Resources