Search Results

Search found 193 results on 8 pages for 'ifdef'.

Page 3/8 | < Previous Page | 1 2 3 4 5 6 7 8  | Next Page >

  • JNI loses reference to native methods

    - by lhw
    As an example for later use in Android I wrote a simple callback interface. While doing so i ran into the following error or bug or whatever. In C the two commented lines are supposed to be executed resulting in calling the C callback onChange. But instead i get an UnsatisfiedLinkError. Calling the native Method directly in Java works just fine. Calling it directly from C as presented here in the example also produces the UnsatisfiedLinkError. I'm open for any advice concerning this issue or work arounds and so on. The Java Part: import java.util.LinkedList; import java.util.Random; interface Listener { public void onChange(float f); } class Provider { LinkedList<Listener> all; public Provider() { all = new LinkedList<Listener>(); } public void registerChange(Listener lst) { all.add(lst); } public void sendMsg() { Random rnd = new Random(); for(Listener l : all) { try { l.onChange(rnd.nextFloat()); } catch(Exception e) { System.out.println(e); } } } } class Inheritance implements Listener { static public void main(String[] args) { System.load(System.getProperty("user.dir") + "/libinheritance.so"); } public native void onChange(float f); } The C Part: #include "inheritance.h" jint JNI_OnLoad(JavaVM *jvm, void *reserved) { JNIEnv *env; (*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_4); inheritance = (*env)->FindClass(env, "Inheritance"); o_inheritance = (*env)->NewObject(env, inheritance, (*env)->GetMethodID(env, inheritance, "<init>", "()V")); provider = (*env)->FindClass(env, "Provider"); o_provider = (*env)->NewObject(env, provider, (*env)->GetMethodID(env, provider, "<init>", "()V")); (*env)->CallVoidMethod(env, o_inheritance, (*env)->GetMethodID(env, inheritance, "onChange", "(F)V"), 1.0); //(*env)->CallVoidMethod(env, o_provider, (*env)->GetMethodID(env, provider, "registerChange", "(LListener;)V"), o_inheritance); //(*env)->CallVoidMethod(env, o_provider, (*env)->GetMethodID(env, provider, "sendMsg", "()V")); (*env)->DeleteLocalRef(env, o_inheritance); (*env)->DeleteLocalRef(env, o_provider); return JNI_VERSION_1_4; } JNIEXPORT void JNICALL Java_Inheritance_onChange(JNIEnv *env, jobject self, jfloat f) { printf("[C] %f\n", f); } The header file: #include <jni.h> /* Header for class Inheritance */ #ifndef _Included_Inheritance #define _Included_Inheritance #ifdef __cplusplus extern "C" { #endif jclass inheritance, provider; jobject o_inheritance, o_provider; /* * Class: Inheritance * Method: onChange * Signature: (F)V */ JNIEXPORT void JNICALL Java_Inheritance_onChange(JNIEnv *, jobject, jfloat); jint JNI_OnLoad(JavaVM *, void *); #ifdef __cplusplus } #endif #endif Compilation: gcc -c -fPIC -I /usr/lib/jvm/java-6-openjdk/include -I /usr/lib/jvm/java-6-openjdk/include/linux/inheritance.c inheritance.h gcc -g -o -shared libinheritance.so -shared -Wl,-soname,libinheritance.so -lc inheritance.o

    Read the article

  • iphone - compiler conditionals

    - by Mike
    Two questions: this code #ifdef __IPHONE_3_0 // iPhone 3.0 specific stuff #else // iPhone 2.2 specific stuff #endif compiles specific codes for specific versions of the iPhone. How could this be transformed to compile for a range of devices? For example: if iphone version < 3.1 or if version = 3.2, and so one... 2) where do I get a list of all conditionals allowed by Xcode? thanks for any help.

    Read the article

  • using #define in a .pch

    - by ML
    Hello All, If I define something in a pre-compiled header like: #define __BUILD_MAC__ and then in a header file do: #ifdef __BUILD_MAC__ typedef void* HINSTANCE; #endif This should work. But for some reason It isn't. I know because when I compile I get errors about HINSTANCE not naming a type. Do I need to do anything else to make these defines available?

    Read the article

  • About inconsistent dll linkage

    - by baris_a
    How can I remove this link warning? You can see code segment that causes this warning. Also Thanks in advance. static AFX_EXTENSION_MODULE GuiCtrlsDLL = { NULL, NULL }; //bla bla // Exported DLL initialization is run in context of running application extern "C" void WINAPI InitGuiCtrlsDLL() { // create a new CDynLinkLibrary for this app new CDynLinkLibrary(GuiCtrlsDLL); // nothing more to do } warning C4273: 'InitGuiCtrlsDLL' : inconsisten t dll linkage I have also export and import definitions, like: #ifdef _GUICTRLS #define GUI_CTRLS_EXPORT __declspec(dllexport) #else #define GUI_CTRLS_EXPORT __declspec(dllimport) #endif

    Read the article

  • Best Way to Include Debug Code?

    - by stormin986
    I am programming Android applications, and the best way here may or may not be the same as Java in general. I simply want to be able to set a debug flag that will only execute certain portions of code when it's set to true––equiv to C++ setting a preprocessor #define DEBUG and using #ifdef DEBUG. Is there an accepted or best way to accomplish this in Java? Right now I'm just going to set a variable in my Application object, but I don't imagine this is the best way.

    Read the article

  • Mimic C preprocessor with Python/Ruby?

    - by prosseek
    I need to mimic the preprocessor feature of C with Python. If I want to run the debug release, I use as follows with C #ifdef DEBUG printf(...) #endif I just use -DDEBUG or similar to trigger it on or off. What method can I use for Python/Ruby? I mean, what should I do to control the behavior of python/ruby scripts in such a way that I can change a variable that affects all the script files in a project?

    Read the article

  • Resource.h in Windows API simple app

    - by nXqd
    there'are these lines in the sample Win32 app created default by VS. Can you explain why they're just numbers, and it's meaning :) //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. // Used by Testing Project.rc // #define IDS_APP_TITLE 103 #define IDR_MAINFRAME 128 #define IDD_TESTINGPROJECT_DIALOG 102 #define IDD_ABOUTBOX 103 #define IDM_ABOUT 104 #define IDM_EXIT 105 #define IDI_TESTINGPROJECT 107 #define IDI_SMALL 108 #define IDC_TESTINGPROJECT 109 #define IDC_MYICON 2 #ifndef IDC_STATIC #define IDC_STATIC -1 #endif // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 130 #define _APS_NEXT_RESOURCE_VALUE 129 #define _APS_NEXT_COMMAND_VALUE 32771 #define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_SYMED_VALUE 110 #endif #endif

    Read the article

  • How to define an extern, C struct returning function in C++ using MSVC?

    - by DK
    The following source file will not compile with the MSVC compiler (v15.00.30729.01): /* stest.c */ #ifdef __cplusplus extern "C" { #endif struct Test; extern struct Test make_Test(int x); struct Test { int x; }; extern struct Test make_Test(int x) { struct Test r; r.x = x; return r; } #ifdef __cplusplus } #endif Compiling with cl /c /Tpstest.c produces the following error: stest.c(8) : error C2526: 'make_Test' : C linkage function cannot return C++ class 'Test' stest.c(6) : see declaration of 'Test' Compiling without /Tp (which tells cl to treat the file as C++) works fine. The file also compiles fine in DigitalMars C and GCC (from mingw) in both C and C++ modes. I also used -ansi -pedantic -Wall with GCC and it had no complaints. For reasons I will go into below, we need to compile this file as C++ for MSVC (not for the others), but with functions being compiled as C. In essence, we want a normal C compiler... except for about six lines. Is there a switch or attribute or something I can add that will allow this to work? The code in question (though not the above; that's just a reduced example) is being produced by a code generator. As part of this, we need to be able to generate floating point nans and infinities as constants (long story), meaning we have to compile with MSVC in C++ mode in order to actually do this. We only found one solution that works, and it only works in C++ mode. We're wrapping the code in extern "C" {...} because we want to control the mangling and calling convention so that we can interface with existing C code. ... also because I trust C++ compilers about as far as I could throw a smallish department store. I also tried wrapping just the reinterpret_cast line in extern "C++" {...}, but of course that doesn't work. Pity. There is a potential solution I found which requires reordering the declarations such that the full struct definition comes before the function foward decl., but this is very inconvenient due to the way the codegen is performed, so I'd really like to avoid having to go down that road if I can.

    Read the article

  • How can I get valgrind to tell me the address of each non-freed block of memory?

    - by James
    Valgrind tells me function xxx allocated memory which was not freed. Fine. It's proving more difficult than usual to trace however. To this end I have created numerous: #ifdef DEBUG fprintf(stderr, "something happening:%lx\n", (unsigned long)ptr); #endif So I just need to match these ptr addresses that are displayed with the addresses of non-freed memory. How can I get valgrind to tell me the address of each non-freed block of memory?

    Read the article

  • Will NKDbgPrintfW be compiled to nop in release build?

    - by Johann Gerell
    I know about and have used the macros DEBUGMSG, RETAILMSG, ERRORMSG, that all take a condition parameter. For general formatted debug output, though, I want to use ::NKDbgPrintfW directly and wonder if someone knows if it compiles to a nop in optimised release builds or if my own macro wrapper around it with #ifdef DEBUG is still needed?

    Read the article

  • glGenBuffers not defined?

    - by user146780
    I'm using windows and I notice that a lot of functions are grayed out because I guess #ifdef GL_GLEXT_PROTOTYPES is not defined. One of these is the VBO extension. Should I just define GL_GLEXT_PROTOTYPES? Otherwise how else can I use VBOs since im using OpenGL32.dll (I want my application to have no dll dependencies not included in Windows by default.) Thanks

    Read the article

  • #include in C# (conditional compilation)

    - by HeavyWave
    Is it possible in C# to set such a condition that if the condition is true - compile one file;If condition is false - compile another file? Sort of like #ifdef DEBUG #include Class1.cs #else #include Class2.cs #endif Or possibly set it up in project properties.

    Read the article

  • gcc run "light" preprocessor

    - by Claudiu
    Is there any way to run the gcc preprocessor, but only for user-defined macros? I have a few one-liners and some #ifdef etc... conditionals, and I want to see what my code looks like when just those are expanded. As it is, the includes get expanded, my fprintf(stderr)s turn into fprintf(((__getreeent())-_stderr), etc...

    Read the article

  • how to separate debug and release mode code

    - by john
    during debug mode or while i am doing testing, i need to print lost of various information, so i use this method ifdef TESTING // code with lots of debugging info else // clean code only endif // TESTING` Is this the good method, or is there any other simple and elegant method. But this way, I am repating the same code in two places and if anything is to be changed later on in the code, I have to do it in both places, which is time consuming and error prone. Thanks. I am using MS Visual Studio.

    Read the article

  • C++ DLL creation for C# project - No functions exported

    - by Yeti
    I am working on a project that requires some image processing. The front end of the program is C# (cause the guys thought it is a lot simpler to make the UI in it). However, as the image processing part needs a lot of CPU juice I am making this part in C++. The idea is to link it to the C# project and just call a function from a DLL to make the image processing part and allow to the C# environment to process the data afterwards. Now the only problem is that it seems I am not able to make the DLL. Simply put the compiler refuses to put any function into the DLL that I compile. Because the project requires some development time testing I have created two projects into a C++ solution. One is for the Dll and another console application. The console project holds all the files and I just include the corresponding header into my DLL project file. I thought the compiler should take out the functions that I marked as to be exported and make the DLL from them. Nevertheless this does not happens. Here it is how I defined the function in the header: extern "C" __declspec(dllexport) void _stdcall RobotData(BYTE* buf, int** pToNewBackgroundImage, int* pToBackgroundImage, bool InitFlag, ObjectInformation* robot1, ObjectInformation* robot2, ObjectInformation* robot3, ObjectInformation* robot4, ObjectInformation* puck); extern "C" __declspec(dllexport) CvPoint _stdcall RefPointFinder(IplImage* imgInput, CvRect &imgROI, CvScalar &refHSVColorLow, CvScalar &refHSVColorHi ); Followed by the implementation in the cpp file: extern "C" __declspec(dllexport) CvPoint _stdcall RefPointFinder(IplImage* imgInput, CvRect &imgROI,&refHSVColorLow, CvScalar &refHSVColorHi ) { \\... return cvPoint((int)( M10/M00) + imgROI.x, (int)( M01/M00 ) + imgROI.y) ;} extern "C" __declspec(dllexport) void _stdcall RobotData(BYTE* buf, int** pToNewBackgroundImage, int* pToBackgroundImage, bool InitFlag, ObjectInformation* robot1, ObjectInformation* robot2, ObjectInformation* robot3, ObjectInformation* robot4, ObjectInformation* puck) { \\ ...}; And my main file for the DLL project looks like: #ifdef _MANAGED #pragma managed(push, off) #endif /// <summary> Include files. </summary> #include "..\ImageProcessingDebug\ImageProcessingTest.h" #include "..\ImageProcessingDebug\ImageProcessing.h" BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { return TRUE; } #ifdef _MANAGED #pragma managed(pop) #endif Needless to say it does not work. A quick look with DLL export viewer 1.36 reveals that no function is inside the library. I don't get it. What I am doing wrong ? As side not I am using the C++ objects (and here it is the C++ DLL part) such as the vector. However, only for internal usage. These will not appear in the headers of either function as you can observe from the previous code snippets. Any ideas? Thx, Bernat

    Read the article

  • Passing an array of an array of char to a function

    - by L.A. Rabida
    In my program, I may need to load a large file, but not always. So I have defined: char** largefilecontents; string fileName="large.txt"; When I need to load the file, the program calles this function: bool isitok=LoadLargeFile(fileName,largefilecontents); And the function is: bool LoadLargeFile(string &filename, char ** &lines) { if (lines) delete [] lines; ifstream largeFile; #ifdef LINUX largeFile.open(filename.c_str()); #endif #ifdef WINDOWS largeFile.open(filename.c_str(),ios::binary); #endif if (!largeFile.is_open()) return false; lines=new char *[10000]; if (!lines) return false; largeFile.clear(); largeFile.seekg(ios::beg); for (int i=0; i>-1; i++) { string line=""; getline(largeFile,line); if (largeFile.tellg()==-1) break; //when end of file is reached, tellg returns -1 lines[i]=new char[line.length()]; lines[i]=const_cast<char*>(line.c_str()); cout << lines[i] << endl; //debug output } return true; } When I view the debug output of this function, "cout << lines[i] << endl;", it is fine. But when I then check this in the main program like this, it is all messed up: for (i=0; i<10000; i++) cout << largefilecontents[i] << endl; So within the function LoadLargeFile(), the results are fine, but without LoadLargeFile(), the results are all messed up. My guess is that the char ** &lines part of the function isn't right, but I do not know what this should be. Could someone help me? Thank you in advance!

    Read the article

  • Under what conditions will you get unresolved external symbol for __declspec(dllimport)?

    - by Mark
    I am converting an application to use .dlls and I'm riddled with linker errors stating unersolved external symbol"__declspec(dllimport) public: void __thiscall Rail::SetNextrail(class Rail *)" There is more gibberish at the end of this error message. Why should this happen and how do you fix it? __declspec(dllimport) is being placed with a macro defined as: #ifdef LUDOAI_EXPORT #define DECLSPECAI __declspec(dllexport) #else #define DECLSPECAI __declspec(dllimport) #endif

    Read the article

  • C++ Win/Linux thread syncronization Event

    - by JP
    Hello I have some code that is cross-platform by unsing #ifdef OS, I have a Queue protected by a CriticalSection on Windows, and by a pthread_mutex_t on Linux. I would like to implement a Wait(timeout) call that would block a thread until something has been enqueued. I though about using WaitForSingleObject on windows but it don't seem to support CriticalSection. Which Win32 and which Linux functions should I use to Wait and Signal for a condition to happen. Thank

    Read the article

  • how to copy files without showing dos window

    - by vinaym
    I have the following code to copy files sprintf(command, "copy /Y %s %s", sourceFile, targetFile); system(command); It works except for the dos window showing up which is very annoying. I am trying to use CreateProcess() (with an #ifdef for WINNT), but not sure how to setup the command line for the same. Any other options for copying files in C (on windows) without showing dos window?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8  | Next Page >