I'm new to C++ but I'm having a hard time working out how to use libcurl with a c++ program.
A) Should I install libcurl with apt-get for the server or install it as some sort of library in C?
B) What is the point of using a c++ binding for libcurl, can I not use it directly without a binding? https://github.com/JosephP91/curlcpp
Sorry if this is obvious.
You need a library to link to. Not quite sure whether apt-get provides that, but checking the project website will probably turn up a download link. Alternatively, you can build the lib from source.
As for the C++ wrapper, you are correct in that you don't need it. It was probably written for the sake of keeping things object-oriented and perhaps to add some convenience. Otherwise you can use it the old C way without any problems.
For commodity sake, always is easier to install with the apt-get/yum or the install system you use in your OS.
A) In my company we have it compiled on one folder. In my house I usually install it from official repositories, I find it easier but it depends if you want to distribute your product and keep your code fixed with one version.
B) That's always up to you, I usually use it directly, I prepare my own eventing system(kqueue/epoll or using libuv/libev/libevent/asio), and assign the callbacks.
A) you have to have the lib installed in your SO's. Otherwise you cannot link it in the program.
B) part1: The point of c++ binding for libcurl, it's for allow you do:
#include "curl_easy.h"
Otherwise you would not be allowed to do it, without implement by yourself the curl_easy.h, remember that it has only C api interface (taken by homepage of libcurl), it allows you to use it because its C but not in native mode.
B) part2: yes you can, but you will need to use the C version of the libcurl. Not the C++ version like you do by the biding.
Related
As the topic says, I'm interested in using some existing c++ code. It is quite much so I don't want to change everything. That's why I'm asking if I have to change the whole code or if it is possible to include it somehow.
As I noticed Android Studio/Gradle wants a CMake file in order to include those external libraries, but my code only includes ordinary makefiles.
Is there any way to make use of the given structure without many changes?
I can't give too much information about the code because it will be too much but here is something about it:
C++ Code
Using Makefiles
(will add more if needed)
Methods I tried:
Ship code inside assets, copy it in the local directory and use then use "make" to compile it on the smartphone - result: permission denied
Use precompiled Unix executable - I couldn't find a right compiler yet (already tested Android standalone toolchain)
Use Android NDK - I didn't manage to include the existing code because the changes were too deep
In my opinion, the best way would be one of the first two options. But I haven't found a way to handle these problems, which are listed above.
What I would like to know is now:
Which option would be the best? Of course, if they're all possible that will depend on the problem, but some opinions would be nice.
How do I know what compiler I have to use?
I am developing part of my R package in C++ using Rcpp and I need to use a Linear Programming Solver.
After comparing some benchmarks using the solvers implementation into R (lpSolveAPI, Rglpk, Rsymphony and so on) I have decided to use GLPK. However, I have found no good way to use it in my C++ code developing under Windows.
Simply put, there is no simple way to just install GLPK and call it using something like
#include <glpk.h>
and I have found no implementations in R packages so that I can use a shortcut using Rcpp attributes like
// [[Rcpp::depends(package)]]
Any ideas?
I'm sure you are aware of the Rglpk package and its predecessor glpk. Often in these cases, it's helpful to stand on the shoulders of those that came before us. Having said that, we gleam from the package sources the following:
The source of Rglpk requires a pre-existing system install, does not enable linking, and is specific to Linux.
The source of glpk installs the library headers directly in R and it seems to also provide direct wrappers into the library.
Given the current implementations and your requirements, you would basically have to create an RcppGLPK package. This is primarily because no one really has a solution for what you need. I would highly suggest that you look at how RcppGSL is structured.
I'm trying to write my first game in c++, and I want it to dynamically load everything from files. This includes the enemies, and I was wondering if there was a way to dynamically include their code at runtime, instead of linking the on compile, so that the levels are easily interchangeable. Lua might be an option but I have no clue where to start, and dll seems to be Windows-only (and I wouldn't know where to start there anyway). Can anyone help with this?
tl;dr I want to link in code to my c++ game at runtime.
For the Lua approach you first need to choose the version first. Right now there is the major version 5.1 and 5.2. My previous work was using 5.1 and for my new project I decided to update to 5.2, however I found that my favorite script wrapping tool (SWIG) does not work with 5.2. Just something to decide at the beginning, because you do not want to get a version working and then have to change it.
Lua comes with makefile build environment. My first experience of trying to build on Windows was a bit of a nightmare, did not appear to just run out-of-the-box, so I opted to create my own Visual Studio project at the time, and just include all the .C files in the project. There are two files which need to selectively included/excluded depending on how you intend to compile: lua.c and luac.c. If you are planning to embed Lua in your app, then exclude both of these files; they both contain a main() function and are designed to build console apps. Include all the rest of the C files in your project.
You should be able to compile easy from this point.
When you include the headers of Lua, keep in mind that the functions are C functions so if you are including them from C++ you need to wrap the file inclusion inside of: extern "C" {} - example: C++ Lua 5.1 Issue
Wrapping your interfaces in another topic and there are lots of resources available. My favorite is SWIG but there are lots of options, including hand coding the conversion of your C/C++ -> LUA -> C/C++ code. Would recommend just focusing on getting the first part working first, get the interpreter embedded so that you can run a "hello, world!" script from Lua inside your app.
So going by your requirement of crossplatform use and dynamic linking, what you're probably looking for is an environment like QT which has QLibrary: https://stackoverflow.com/a/9675063/453673
But https://softwareengineering.stackexchange.com/questions/88685/why-arent-more-desktop-apps-written-with-qt
MingW is the open-source equivalent for Visual C++, so it can help you writing code for Windows (though if I had a choice, I'd directly use Visual C++). The way dll's are loaded in Windows is somewhat similar to the way they're loaded in Linux, so you'll be able to write code with #ifdef's to do conditional compilation. I've written one such program a couple of years back.
To load a shared library(always with .so as suffix) under Linux, you could use dlopen(), dlsym() and dlclose()
I am working on a large open source C++ program that uses the R standalone library (libRmath, Ubuntu/Debian package r-mathlib). I want to remove this dependency: I'd like to include the source code from the R standalone library in my source tree, without the entire R source code. Can this be done?
Unfortunately, the R standalone library seems tightly coupled to the rest of the R code. In the standard R source tarball, the same configure script is used for the main package and the standalone library. This configure script doesn't play well on different platforms. I am hoping that the standalone library is available as its own "standalone" source tree.
Related note: I've looked at the Rinside library, particularly via this thread. I think the method I am describing would make distribution easier, for 2 reasons: 1) users that already have R installed won't have to reconfigure their installation (and can maintain a different version as their default installation); 2) users without R won't have to install it.
Update: fixed a typo - I'd originally referred to Rinside as Rinclude
A few points for you:
Can this be done? Of course it can, just copy and paste the code for r-mathlib into your project. The licensing for that library is a very liberal LGPL. Now, is it a good idea? I don't think so. Shared libraries have upside in that you get bugfixes, easier and shorter build etc/
Seems tightly coupled to the rest of the R code. No, that is factually incorrect. The whole point of r-mathlib is that you can depend just on it. I think it may still needs R headers on your system but if you define the MATHLIB_STANDALONE variable. E.g., on my Ubuntu box I just did gcc -o /tmp/rmathTest /usr/share/doc/r-mathlib/examples/test.c -lRmath -lm and the resulting binary depends on libRmath alone, not libR.
Configure script doesn't play well on other platforms. That is a bold statement, don't make it anywhere near Prof Ripley. R is amazingly portable, and I fear your claim is a little lacking in empirical basics here.
What you are after can be done in different ways, and has been done in different ways.
And yes there is ample documentation as well. Start with 'Writing R Extensions' and 'R Admin + Inst' and by all means come back with follow-up questions.
Lastly, in case you change your mind and you do want R inside C++, you may want to consider RInside as well. That does however create a depedencies on R, Rcpp and RInside itself.
I'm a total noob when it comes to linking and building with Visual Studio. I would like to integrate Lua into my C++ console application.
Can someone give a step by step on how to do this from getting the Lua dependencies from lua.org, to actually running a "Hello World from Lua" in VS, and all the steps in between.
Finding something like this online has been very difficult since most require prerequisite knowledge of building Lua and such.
Thanks :)
Start with the Lua for Windows package. It will get you a self-contained batteries included Lua installation. Lua for Windows is not an official distribution, but it is well respected by the Lua user community. You can use its lua.exe to gain experience with the language in a Windows environment, and its rich collection of tested extension modules is also available for use.
If you add its include and lib folders to your VS project configuration, you should be able to compile and link against Lua in short order.
One possible complication is that the LfW distribution is built against VC8's C runtime library. If that becomes a problem, then you can either compile Lua yourself as part of your Solution, or get a known good DLL that matches your specific version of Visual Studio from the Lua Binaries project.
Do remember that if you are using one of the distributed DLLs, it will have been compiled as C, and not C++. That means that you must wrap any references to the Lua include files in extern "C" {...} or you will have problems with linkage.
It really helps to have some experience with VS project configuration and building. In particular, experience with mixing C and C++ in a VS project is very helpful.
I heartily recommend following the advice already given about learning C and C++ and mixing the two together. Once you have that under your belt, you may want to check out LuaBind or LuaPlus for connecting C++ and Lua. You can do it manually (and you probably should, at first, to understand what's going on under the hood), but it's more efficient and cleaner, code-wise, to use one of those binding libraries. For debugging purposes, Decoda is a good choice; it can attach to processes started in VS which contain Lua code you want to check.