3 ms·
Do you mean link as in "linker"? Or are you asking if it's possible to do "using LibX" like in C#? You can already do "using ClassX", but yeah, the package man
by kevinnk 11y ago
Do you mean link as in "linker"? Or are you asking if it's possible to do "using LibX" like in C#?
You can already do "using ClassX", but yeah, the package management story in C++ isn't great.
There's a proposal for modules in C++[1], which should help, but as far as I know that's not going to be in C++17. Clang already has a (different) version implemented as well[2].
[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4465.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n446...
[2] http://clang.llvm.org/docs/Modules.html http://clang.llvm.org/docs/Modules.html
- maxxxxx 11y agoI meant compiling C++ code into a shared library like a DLL on Windows and be able to use the classes in that DLL from other code. The same way you can easily call C code in different libraries.
- meetingcpp 11y agoWell, that has been done for decades. You just need to link your code with the correct libraries. Its probably a bit easier with C as it has a common ABI, and C# as it only has one tool chain, and not multiple toolchains from multiple vendors like C++. Modules will help here further.
- kevinnk 11y agoI believe maxxxxx is asking about the ability to import and use classes from a DLL directly, without needing a class definition. As far as I know, in standard C++ this isn't possible.
- meetingcpp 11y agoYes, that is correct. That is not possible, modules might offer things in this direction.
- maxxxxx 11y agoYes, that's it. Thank you! This is the one thing I really like about .NET. C++ would be so much more accessible to beginners if it was easier to integrate other libraries. Even integrating something as common as boost is quite hard with Visual Studio on Windows.
- kazinator 11y agoC++ doesn't define any object format, period. A C++ implementation could provide translated units which encapsulate not only compiled code, but also contain compiled class declarations, such that these units can just be used without any preprocessing, tokenizing or parsing. That would be outside the language. The C++ language as it stands is defined in terms of a textual representation: everything proceeds from translation units being scanned into preprocessing tokens and so forth. To use a compiled class declaration, you would still need to see the source code somewhere, in some form, in some documentation. Otherwise, how would you know that the frobozz class has a freakout method which accepts two int parameters.
- Kliment 11y agoAbout the last bit, a long time ago I would use the ctypes library in Python to inspect, list, and call functions defined in .DLLs. All the symbol exports are right there in the object file, so for non-C++ callers you don't exactly need the source code to call functions. It doesn't seem like a large stretch to ask whether the same thing can be done with classes, or to expect that this particular aspect would have changed sometime in three iterations of the standard.
- deleted 11y ago[deleted]
- kevinnk 11y agoAh, I understand. Currently in C++ you cannot inspect class members or call methods without a class definition (i.e. the class header file). For the most part, the C++ standard doesn't really consider the object layout "in scope" so it's unlikely we'll see something like this standardized in the near future. This could change (maybe if/when reflection is added?) but nothing like it is being talked about AFAIK.