-
Calling Java Subroutine
I have a C++ program and I would like to use "HTTP GET" in a subroutine. I more or less have this subroutine in Java, but I don't know how to call it from C++. LIBCURL might be good, but I don't know how to use that either. Are there any good example codes on the web where Java is called from a C++ program? I'm on Windows, if that matters.
-
Use libcurl. It's easy enough to use. Lots of sample code.
-
I have the libcurl header files in a folder in my working directory. I also have libcurl.dll in my working directory. I can't seem to compile the following program:
Code:
#include <stdio.h>
#include "curl/curl.h"
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
I type
and I get all this stuff about undefined references:
"undefined reference to '_imp__curl_easy_setopt'"
"undefined reference to '_imp__curl_easy_init'"
"undefined reference to '_imp__curl_easy_perform'"
"undefined reference to '_imp__curl_easy_cleanup'"
-
libcurl should come with libcurl.lib. You need to add this to the libraries in the linker options.
-
What compiler are you using? I generally use the #pragma directive instead of going into the linker options. So that would require a
Code:
#pragma comment( lib, "libcurl.lib" )
which should set the linker up and it should work.
-
-
-
Lets back up just a second and I let me make an alternative suggestion. Is the crux of the problem simply that your HTTP fetching functions are written in Java? If so, why not just port your code over to C(++)? I think it would be an equally simple option. Though, I do not know your level of programming either. So its impossible to say for certain.
-
Or if the web stuff you need to do isn't very complicated there are other solutions... This is one (change the pragma to link options) http://cboard.cprogramming.com/showp...57&postcount=9
-
See there ya go. And even if it is terribly complicated I don't think integrating Java code just within this particular context is the most efficient way to go about things.
-
The program already exists in Java. If I port it over to C++, I will probably have to use libcurl. Since I am using MinGW, libcurl is not supported with my compiler and it is thus not guaranteed to work. I could use MSVC++, although I would prefer not to. Perhaps I will need to use MSVC++.
-
I use gcc and libcurl.... So it should be compatible with mingw. If not, don't use a minimal gcc like mingw, use the real deal.