'mutex': is not a member of 'std', error when using Armadillo in CLR - c++-cli

I am using Armadillo in c++ CLR, when I include armadillo in my solution and building it, I get this error:
missing type specifier - int assumed. Note: C++ does not support default-int
'mutex': is not a member of 'std'
'cache-mutex':unknown override specifier
Here is my code and I have not written anything yet:
#include "pch.h"
#include <include/armadillo>
using namespace System;
int main(array<System::String ^> ^args)
{
}
How can I solve this issue?

Define a macro named ARMA_DONT_USE_STD_MUTEX before #includeing the armadillo header. Example:
#define ARMA_DONT_USE_STD_MUTEX
#include <armadillo>
The documentation says:
ARMA_DONT_USE_STD_MUTEX
Disable use of std::mutex; applicable if your compiler and/or environment doesn't support std::mutex

Related

Class template argument type deduction in C++17 - compilation problems

I'm following Kate Gregory's C++ course on Pluralsight and understand that C++17 introduced a feature for compilers to deduce the type in a template, however the code below returns the error: missing template arguments before 'numbers'
#include <vector>
using std::vector;
int main()
{
vector numbers{ 0, 1, 2 };
return 0;
}
I'm using the MinGW gcc compiler (version 6.3.0) and using "g++ -std=c++1z *.cpp" in the command prompt, so I'm not sure what I'm doing wrong.
I know I can fix it by declaring the type but I wanted to check in case I miss out on other C++17 features through some basic error I'm making.
Your code is OK (but I suggest not to use using std::vector).
The problem is your compiler, g++ 6.3.0, that is too old to support the feature you're trying to use: class template argument deduction and deduction guides.
You need g++ 7 or newer.

What compiler option/library do I need to use detect_or_t type trait?

I am trying to use std::experimental::detect_or_t from <experimental/type_traits>.
What compiler, option, version or library do I need to compile the following example from http://en.cppreference.com/w/cpp/experimental/is_detected ?
#include <experimental/type_traits>
#include <cstddef>
template<class T>
using diff_t = typename T::difference_type;
template <class Ptr>
using difference_type = std::experimental::detected_or_t<std::ptrdiff_t, diff_t, Ptr>;
struct Meow { using difference_type = int; };
struct Purr {};
int main()
{
static_assert(std::is_same<difference_type<Meow>, int>::value, "Meow's difference_type should be int!");
static_assert(std::is_same<difference_type<Purr>, std::ptrdiff_t>::value, "Purr's difference_type should be ptrdiff_t!");
}
I tried using clang++ -std=c++14 and g++ -std=c++14. Also with -std=c++1y and -std=c++17. I always get this:
main.cpp:8:44: error: 'detected_or_t' in namespace 'std::experimental' does not name a template type
Those traits were first added to libstdc++ in GCC 6.1.0, as documented in the GCC 6 release notes:
Experimental support for most features of the second version of the Library Fundamentals TS.
And the implementation status tables in the manual, at
https://gcc.gnu.org/onlinedocs/gcc-6.1.0/libstdc++/manual/manual/status.html#table.cxx1z_ts_status
I'm less sure about libc++, but they're not supported by the version in Clang 3.9.1 but are supported by the current trunk, so I think they first appeared in Clang 4.0.0

unresolved external symbol while using a library

i have a header file named NetworkInterfaceInfoProvider.h.
in this header file i declare a class as follow:
#ifndef INETWORK_INTERFACE_INFO_PROVIDER_H
#define INETWORK_INTERFACE_INFO_PROVIDER_H
#pragma once
/*#include "stdafx.h"*/
#include "IConfig.h"
#include "NetworkAddapterAddresses.h"
#include "InstaledAddapters.h"
namespace IRNetwork
{
class CLASS_DECLSPEC INet;
struct CLASS_DECLSPEC GenericIPAddress;
/*
* provide information about all network interface related adapters such as installed interfaces , addresses , best routes and ...
* TO DO: implement Other OS's
*/
class CLASS_DECLSPEC INetworkInterfaceInfoProvider
{
public:
INetworkInterfaceInfoProvider(void);
~INetworkInterfaceInfoProvider(void);
int32_t GetBestRouteTo(char* destIp,uint16_t port,ip_t *ip);
int32_t GetBestRouteTo(GenericIPAddress* ip);
private:
INet* snet;
};
}
#endif
when i want to use it in my console application i got following linker error
*note: the library of above code has been linked to my console application.
CLASS_DECLSPEC is dll import/export definition*
error LNK2019: unresolved external symbol "__declspec(dllimport)
public: int __thiscall
IRNetwork::INetworkInterfaceInfoProvider::GetBestRouteTo(char
,unsigned short,char ()[65])" (_imp?GetBestRouteTo#INetworkInterfaceInfoProvider#IRNetwork##QAEHPADGPAY0EB#D#Z)
referenced in function "void __cdecl test_adapters(void)"
(?test_adapters##YAXXZ) testDhcpv4.obj testDhcpv4
what is wrong here?
Hmm. From the error I would say importing looks good. So maybe there was an error while exporting. Assuming you are using Visual Studio, you can use dumpbin to check if your dll is exporting correctly:
Open the Visual Studio Command Prompt (available from the windows start menu) and type
dumpbin /EXPORTS yourlib.dll
Then you should see our export, something like (dump from one of my dlls):
...
170 A9 00108120 ??1AbstractParam#param#core#megamol##UAE#XZ = ??1BoolParam#param#core#megamol##UAE#XZ (public: virtual __thiscall megamol::core::param::BoolParam::~BoolParam(void))
...
If the function your are calling is not listed, you should doublecheck if your dllexport is set correctly while building your dll.
If the function is listed, but looks different, you should check for the calling conventions to be the same for your application and your dll.
If the function is listed and the name looks identical to what the error message says, doublecheck if you are linking the import library of the dll correctly.
Also check if the runtime-configuration is the same for your application and your dll (e.g. Multi-Threaded-Dll or Multi-Threaded-Debug-Dll).

#include <malloc.h> -- Xcode

I have an interesting problem where I can't include malloc.h in my project.
I need malloc.h for Paul Nettle's mmgr tool (I'm not keen on using instruments)
Problem is I can't find the system library for memalign.
Xcode keeps failing because it cannot this definition & neither can I.
Anyone else seen this?!
If you just need to use malloc then you can grab it from the stdlib like so:
#include <stdlib.h>
Otherwise, you can directly call malloc.h like so:
#include <malloc/malloc.h>
EDIT:
A posix_memalign() exists in stdlib.h. The implementation looks like:
int posix_memalign(void **, size_t, size_t);
Perhaps you can make an alias to this and use it?

HashMap : Dealing with Managed objects C++

I guess it's kind of a stupid question but here is my problem :
I want to have a hash_map<int, Object^> as an attribute of my object BigObject, which is written in managed C++.
So I have to declare a pointer, hash_map<int, Object^>* hash because I cannot declare explicitely native object in managed code.
How can I insert an object ? the hash_map[] won't work with a pointer, and I cannot make insert work (I cannot use a std::pair<int, Object^> because Object is managed...
Thanks a lot
You should declare your hashmap as hash_map<int, gcroot<Object^> >. You will need to #include <vcclr.h>
See also msdn
edit: added code sample
#include <iostream>
#include <vcclr.h>
#include <hash_map>
using namespace std;
using namespace stdext;
using namespace System;
int main()
{
hash_map<int, gcroot<Object^> > hash;
hash.insert( make_pair<int, gcroot<Object^> >( 5,
gcnew String("hello world") ) );
return 0;
}
If you're working in .NET, why not use one of the .NET collections? They are directly usable in C++/CLI, and can also be shared with other .NET languages, which a std::hash_map cannot. And they play nicely with the garbage collector.
.NET provides several hashtable implementations, including 'System.Collections.HashTable' and System.Collections.Generic.Dictionary.
In your case, a Dictionary<int, Object^>^ would be appropriate.
hash_map <double,gcroot<siteNEVObjectdic^>> d;
d.insert(make_pair<double,gcroot<siteNEVObjectdic^>>(PN2,gcnew siteNEVObjectdic(Lat1,Long1,Lat2,Long2,Lat3,Long3)));
this worked as a charm.