generated wrapper java file from interface header file by swig is empty - cmake

My generated example.java has no code from the interface specified in the header file.
example.i:
%module example
%include "std_string.i"
%{
#include "storagepoc/storagepoc.h"
%};
using namespace std;
typedef std::string String;
%include "storagepoc.h";
storagepoc.h:
#ifndef STORAGEPOC_H
#define STORAGEPOC_H
#include <string>
class Aws::S3::S3Client;
namespace storagepoc {
class StoragePOC {
public:
/* Constructor */
StoragePOC(const std::string &options);
/* Destructor */
~StoragePOC();
/* Copy image */
std::string CopyImage(const std::string &input_url, const std::string
&storage_url, const std::string &options);
private:
std::shared_ptr<Aws::S3::S3Client> m_client;
};
}
#endif
CMakeLists.txt:
SET(CMAKE_SWIG_FLAGS -package com.intel.proxy)
swig_add_library(example LANGUAGE java TYPE USE_BUILD_SHARED_LIBS SOURCES
example.i)
SWIG_LINK_LIBRARIES(example storagepoc)
# For convenience we copy the dynamic library to the current build folder
add_custom_command(
TARGET example
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:example>
${CMAKE_CURRENT_BINARY_DIR}
)
# Build the Java code into ExampleJNI.jar
add_jar(
ExampleJNI
SOURCES
VERSION 0.0.1
${CMAKE_SWIG_OUTDIR}/example.java
${CMAKE_SWIG_OUTDIR}/exampleJNI.java
)
add_dependencies( ExampleJNI example )
#link ExampleJNI with its dependencies
#target_link_libraries(ExampleJNI example)
# Finally build the demonstration code into Main.jar
set(CMAKE_JAVA_JAR_ENTRY_POINT main)
add_jar(
Main
SOURCES main.java
VERSION 0.0.1
ENTRY_POINT main
)
add_dependencies( Main ExampleJNI )
The generated example.java is empty ???
The exampleJNI.java has the generated interface methods - StoragePOC_CopyImage...
My earlier example.java was using a
%inline %{
namespace jni {
extern int foo();
}
%}
and this generated an example.java wrapper file ??
TIA

Had to add the following to my example.i:
%pragma(java) modulecode=%{
public static String CopyImage(String input_url, String storage_url, String options) {
return new StoragePOC(options).CopyImage(input_url, storage_url, options);
}
%}
Section 21.4.2.1 http://www.swig.org/Doc1.3/Java.htm

Related

HPDF_SetCompressionMode() not working in Libharu

I am generating Pdf files using LibHaru libraries. My code is following
#include <iostream>
#include "hpdf.h"
using namespace std;
void error_handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void *user_data)
{
}
int main()
{
cout<<"Compression"<<endl;
HPDF_Doc pdf = HPDF_New(error_handler, NULL);
if (!pdf)
return 0;
HPDF_STATUS Status = HPDF_SetCompressionMode(pdf, HPDF_COMP_ALL);
return 0;
}
PROBLEM: I debugged the code and found that HPDF_SetCompressionMode() returns 4129, which is the error code for Invalid value set when invoking HPDF_SetCommpressionMode(). .
If you step into the code, you will see you are getting the error because the ZLIB compression library was not compiled into your copy of HaruPDF.
First: comment out this line in ..\win32\include\hpdf_config.h:
/* zlib is not available */
//#define LIBHPDF_HAVE_NOZLIB
Second: find, download and unzip the ZLIB code. You can obtain the source from the following Website:
http://www.zlib.net/
Third: tell HaruPDF where it can find the ZLIB code, and recompile HaruPDF.
You should now be able to use compression.
Ain't Open Source grand?

CLion show me an error when I use a new signal-slot connect function with Qt5

I'm developing Qt5 application, but when I use a new signal-slot connect function, CLion will show me error, "Incompatible pointer types 'const char ' and 'void()(bool)'". I'm sure the lib is Qt5. How should I do to solve the problem.
This is my code(OS X 10.11.3).
// KSMainWindow.cpp
#include "KSMainWindow.h"
#include <QMenuBar>
#include <QToolBar>
#include <QDebug>
KSMainWindow::KSMainWindow(QWidget *parent) : QMainWindow(parent) {
setWindowTitle(tr("KSText"));
openAction = new QAction(tr("&Open..."), this);
saveAction = new QAction(tr("&Save..."), this);
QMenu *file = menuBar()->addMenu(tr("&File"));
file->addAction(openAction);
file->addAction(saveAction);
textEdit = new QTextEdit(this);
setCentralWidget(textEdit);
connect(openAction, &QAction::triggered, this, &KSMainWindow::openFile);
connect(saveAction, &QAction::triggered, this, &KSMainWindow::saveFile);
}
KSMainWindow::~KSMainWindow() {
delete openAction;
delete saveAction;
delete textEdit;
}
void KSMainWindow::openFile() {
qDebug() << "Open";
}
void KSMainWindow::saveFile() {
qDebug() << "Save";
}
CLion hope the &QAction::triggered convert to const char *.
This is my CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(demo8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(EXECUTABLE_OUTPUT_PATH ./bin)
find_package(Qt5 REQUIRED COMPONENTS Widgets Core Gui)
aux_source_directory(./src SRC_LIST)
add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${SRC_LIST})
qt5_use_modules(${PROJECT_NAME} Widgets Core Gui)

DLL import failure in using WinDivert

I am going to design a program using WinDivert to manipulate the network traffic.
The language I use is C++ and the program is designed under Visual Studio 2008.
Firstly I create a project in visual C++ CLR (Windows Forms Application) so I can implement the UI simply.
For importing the WinDirvert Library, I have done the following setting in project properties:
Configuaration Properties: General
Common Language Runtime support: Common Language Runtime Support(/ctr)
Configuaration Properties: Linker
Additional Dependencies: link of WinDivert.lib
Module Definition File: link of windivert.def
Within the project I have created, I also added the windivert.h in the header files.
Also, windivert.h is included in the main entry point of my project (ProjectG.cpp):
#include "stdafx.h"
#include "Form1.h"
#pragma managed(push, off)
#include "windivert.h"
#pragma managed(pop)
using namespace ProjectG;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
HANDLE handle;
unsigned char packet[8192];
UINT packet_len;
WINDIVERT_ADDRESS addr;
handle = WinDivertOpen("udp", WINDIVERT_LAYER_NETWORK, 0,
WINDIVERT_FLAG_DROP);
if (handle == INVALID_HANDLE_VALUE)
{
Application::Exit();
}
while (TRUE)
{
// Read a matching packet.
if (!WinDivertRecv(handle, packet, sizeof(packet), &addr, &packet_len))
{
MessageBox::Show("Fail");
continue;
}
}
return 0;
}
Finally, I put the {WinDivert.dll, windivert.h, WinDivert.lib, WinDivert32.sys} under the project directory.
However, the following error is shown:
fatal error LNK1306: DLL entry point "int __clrcall main(cli::array<class
System::String ^ >^)" (?main##$$HYMHP$01AP$AAVString#System###Z) cannot be managed;
compile to native ProjectG.obj ProjectG
Additional: (a warning)
warning LNK4070: /OUT:WinDivert.dll directive in .EXP differs from output filename
'C:\Users\David\Desktop\css\ProjectG\Debug\ProjectG.exe'; ignoring directive
ProjectG.exp ProjectG
Question:
How can I resolve this situation?
a) your main source is .cpp, so you can delete [STAThreadAttribute] and change
int main(array<System::String ^> ^args) to int _tmain(int argc, _TCHAR* argv[])
b) exclude windivert.def from linker Module Definition File, this only when you are creating a DLL
c) the DLL/SYS files would need to be copied to the Debug and Release folders

Calling a dll from fortran

I am aiming at calling a dll file from a fortran compiler. I am doing all this in windows using the mingw compiler.
The dll was created using a g++ compiler
The code for which I am trying to create a dll
// example_dll.cpp
#include <stdio.h>
#include "example_dll.h"
__stdcall void hello()
{
printf("Hello");
}
command entered in the command prompt
g++ -c -DBUILDING_EXAMPLE_DLL example_dll.cpp
g++ -shared -o example_dll.dll example_dll.o -Wl,--out-implib,libexample_dll.a
The above two commands creates the dll file.
The job now is to create a fortran script to compile the dll file previously created.
For this purpose I am looking forward to create a fortran file capable of linking to the dll previously created.
Any help will be appreciated.
Thanks,
Adarsh
Later I tried some of the possibilities. My updated files are as follows
C file for which the DLL is created is as follows
// example_dll.c
#include <stdio.h>
#include "example_dll.h"
EXPORT void tstfunc (void)
{
printf("Hello\n");
}
EXPORT int Double11(int x)
{
printf("From the Double11\n");
printf("%d\n",x);
return x;
}
.h file used to create the DLL is as follows
// example_dll.h
#ifdef EXAMPLE_DLL_H
// the dll exports
#define EXPORT __declspec(dllexport)
#else
// the exe imports
#define EXPORT __declspec(dllimport)
#endif
// function to be imported/exported
EXPORT void tstfunc (void);
EXPORT int Double11(int x);
Fortran file used to link the dll is as follows
! fortcall.f90
program ForCall
IMPLICIT NONE
integer :: sum
integer :: inte3
INTERFACE
SUBROUTINE write() BIND(C,NAME='tstfunc')
END SUBROUTINE write
END INTERFACE
INTERFACE
SUBROUTINE get_integer(inte,inte2) BIND(C,NAME='Double11')
USE ISO_C_BINDING
IMPLICIT NONE
INTEGER (C_INT), VALUE :: inte
INTEGER (C_INT), INTENT(OUT) :: inte2
END SUBROUTINE get_integer
END INTERFACE
CALL write
CALL get_integer(1,inte3)
print*,"the output is",inte3
END PROGRAM ForCall
After entering the following directive in the command prompt
gfortran -o dll_foo_test fortcall.f90 -L. example_dll.dll
The output will be as follows
Hello
From the Double11
1
the output is -2
At this point something is not right. The code is capable of passing a value from FORTRAN to the DLL, whereas the code is not returning the right value from the dll. Some junk value of -2 is being displayed instead of 1.
I would like to fix that part in the code.

error when compile lex.yy.c with g++

i have written a bison, flex and c++ files.
Compilation of bisoon and flex was passed. But when i'm trying to compile the c and cpp files:
g++ *.cpp *.c, i get strange error:
lex.yy.c:479: error: expected `;' before "static"
and when i opened lex.yy.c file, i see code that was automatically created by flex. This is some part of code around line 479, line 479 is bold:
using namespace std;
using namespace output
#line 465 "lex.yy.c"
/* Macros after this point can all be overridden by user definitions in
* section 1.
*/
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
extern "C" int yywrap YY_PROTO(( void ));
#else
extern int yywrap YY_PROTO(( void ));
#endif
#endif
#ifndef YY_NO_UNPUT
static void yyunput YY_PROTO(( int c, char *buf_ptr ));
#endif
#ifndef yytext_ptr
static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
#endif
i don't have any idea what to do. Please help me.
thanks
You should`t try to fix the error in file generated by lex, instead of it you need to check your lex specification for errors.
UPDATE:
Possible place to look for source of such mistake is lex specification user code section. As it is noticed in comments, LEX isn`t checking code that it generates from the specification.