I just recently started working with c++ templates in order to use a template I know you do template<typename T> class MyClass, but how do I apply a filter? In C# you can do public class MyClass<T> where T:filterClass and in Java it's public class MyClass<T extends/implements filterClass>. I've tried following the tutorial at https://msdn.microsoft.com/en-us/library/a174071k.aspx but my compiler doesn't recognize the flag -clr or the keywords generic and where. I've looked on cppreference.com and cplusplus.com and couldn't find anything. Using the --version option on my compiler returns g++ (Ubuntu 5.4.0-6ubuntu~16.04.1) 5.4.0 20160609. I am also using c++11 and would prefer not to use external libraries.
Related
I've been looking into online resources on writing GCC plugins. I'm currently using GCC version 7.3.0. I attempted writing a simple plugin that contained a callback which would be called upon PLUGIN_FINISH_TYPE. It worked fine.
Next, I'm trying to write a plugin that uses a "gimple pass" similar to the example listed here. However, struct gimple_opt_pass does not seem to exist.
I tried looking for header files that declare this struct. I found that tree-pass.h has the following code block :-
/* Description of GIMPLE pass. */
class gimple_opt_pass : public opt_pass
{
protected:
gimple_opt_pass (const pass_data& data, gcc::context *ctxt)
: opt_pass (data, ctxt)
{
}
};
How can I see this from within my plugin? I don't seem to be able to use this in the way as described in the link above.
With the current GCC plugin API, is it possible to write a pure C plugin(as opposed to having to use C++).
I've found the answer. The API for GCC plugins changed dramatically from 4.8 to 4.9. Uptil 4.8, gimple_opt_class was a structure that you could create an instance of and use with register_pass_info. From 4.9 onward, it is a class that you would need to inherit from, create an instance of and use with register_pass_info.
In order to be able to use pure C plugins with GCC, it would seem like using the API for version below and including 4.8 would be the solution. 4.6 seems to be working fine for me, but does to seem to have debug/dump functionality in it.
I am building a C ++ library for Windows, Linux / Unix based on CMake.
I create a shared library(.dll) on Windows, and I want to use a static library(.a) on Linux / Unix.
On Windows, I know how to do __declspec(dllexport/dllimport) for every function and class I want to export.
Then I saw these articles recently. (https://blog.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/)
I tried to build CMakeLists.txt without __declspec() in the library function as described in the article.
include(GenerateExportHeader)
generate_export_header(mylibrary)
According to the article, in order to export the static member variables in the class, it is necessary to create the export header according to the existing method and to declare the variables as below.
#include <mylibary_export.h>
class MyClass
{
static mylibrary_EXPORT int GlobalCounter;
...
}
The library has been compiled successfully, but attempting to reference this GlobalCount variable in the downstream project results in a LINK error.
Do you have an idea on this issue?
I think I found a bug in the libc++ list implementation. The following code will produce a compiler error (Field has incomlete type 'foo') when using certain build settings in xcode:
#include <list>
using namespace std;
class foo {
public:
list<foo> bar;
};
The settings are the following:
XCode Version: 4.4.1
C++ Language Dialect: C++11 or GNU++11
C++ Standard library: LLVM C++ standard library with C++ extensions (libc++11)
Using GCCs libstdc++ will resolve the error.
Not using the C++11 dialect will resolve the error.
Using vector instead of list will resolve the error.
I think it is a bug in the list implementation, but I am not sure.
Forgive my ignorance, but I don't know what I should do to resolve this issue.
Switching to vector is not an option in my project and I definitely need C++11 features. That also includes shared_ptr, but the headers are missing when using GCC. Beside that, apple does not seem to provide new versions of GCC anymore.
I would very appreciate it if somebody could recreate this issue, maybe with newer header from libc++.
Also, if updating LLVM/libc++ would resolve this issue, do you recommend it?
C++ Standard 17.6.4.8:
In certain cases (replacement functions, handler functions, operations on types used to instantiate standard library template components), the C++ standard library depends on components supplied by a C++ program. If these components do not meet their requirements, the Standard places no requirements on the implementation.
In particular, the effects are undefined in the following cases:
...
if an incomplete type (3.9) is used as a template argument when instantiating a template component,
unless specifically allowed for that component.
None of the standard library's container class templates, including list, mention any such allowance for an incomplete type. So your program is an invalid one that might happen to work with some compilers. That can't be considered a bug in the standard library implementation.
I have a set of software library modules which are developed in c++. So, I use g++ to compile my software.
This has to be used by various existing applications which are written in C and compiled with gcc.
When the other teams used g++ to compile their code, they started getting lot of compiler errors due to strict type checking rules of c++. This broke their applications. Worse still, they are using some 3rd party library code, which cannot be compiled using g++.
if they use gcc, then there are linker errors (unresolved symbols).
so, my question is...
"Is there a way for my library code to be linked with their applications, without changing the respective compilers? That is, i still have to use g++, since i use classes/objects heavily in my code, and they have no choice of using g++, which will break their application?".
Thank you for kind help.
regards,
Ravindra
One of the problems you may be experiencing could be the result of different versions of g++ having different ABI formats. at very least, don't expect versions of G++ prior to 4.1 to work with code compiled with 4.1 or later.
Intermingling C and C++ requires that the C++ code all export a C compatible interface. This is done by declaring free functions (cannot be used on classes) with the extern "C" specifier. (some notes on the c++ faq lite_
extern "C" {
#include "c_language_headers.h"
int c_accessible_function(int);
struct c_accessible_datatype { };
}
I am encountering some issues with one project. I need to use two libraries but one needs to be compiled with the /clr switch as the other cannot be compiled with this switch.
Would there be a way to use at the same time those two libraries in one project? Currently it's compiled with /clr and I got linking errors with the noclr library.
If there is no solution I can still launch the noclr library in batchmode but I'd like to avoid it...
My project is in Managed C++, the library tetgen - which needs /clr - is in native C++ and cannot be compiled without the /clr switch, as I get this error
error C3381: 'tetgenio' : assembly access specifiers are only available in code compiled with a /clr option
The other library triangle is in C. I am on Visual Studio 2008 and the project is compiled in 32 bits.
We could use more details, but using managed C++ you can certainly use a mix of managed and unmanaged code. (Microsoft calls their managed c++ code C++/CLI.)
EDIT:
Ok, your compiler error helped. Apparently you have specified a native class, but using public private, or some other access specifier on the name of the native class. From the MSDN docs:
The following sample generates C3381:
// C3381.cpp
**public** class A { // C3381. Remove public or make the class
managed. };
int main() { }
so get rid of the public keyword, and then try compiling again.
You can have multiple projects in a single solution. Right click on the solution in the eolution explorer and add -> existing/new project. Each library project can be added that way and have their own clr settings.