views:

428

answers:

1

Hey Folks i am trying to compile this C++ program:

#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h> 
#include <Windows.h>
#include "Validate.h"    

JNIEXPORT jstring JNICALL Java_Validate_takeInfo(JNIEnv *env, jobject obj,
        jstring domain, jstring id, jstring idca, jstring password) 
{
    const char *nt_domain;
    const char *nt_id;
    const char *nt_idca;
    const char *nt_password;

    nt_domain = env->GetStringUTFChars(domain, NULL);
    nt_id = env->GetStringUTFChars(id, NULL);
    nt_idca= env->GetStringUTFChars(idca, NULL);
    nt_password = env->GetStringUTFChars(password, NULL);

        HANDLE hToken = 0;
    char *otherString;
    bool aut;

        aut = LogonUser(nt_id, nt_domain, nt_password, LOGON32_LOGON_NETWORK,
                    LOGON32_PROVIDER_DEFAULT, &hToken );
    if(aut)
    {
     otherString = "true";
    }
    else
    {
     otherString = "false";
    }
    jstring newString = env->NewStringUTF((const char*)otherString);
    return newString;
}

int main()
{
    return 0;
}

Using this command:

cl -I"c:\Program files\Java\jdk1.5.0_07\include"
   -I"C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include"
   -I"c:\program files\java\jdk1.5.0_07\include\win32"
   -LD D:\JNI\%filename%.cpp -D:\JNI\Fe%filename%.dll -link
   -LIBPATH:"C:\Program Files\Microsoft Visual Studio 8\VC\lib"
   -LIBPATH:"C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib"

However i always get the following error:

Validate.obj : error LNK2019: unresolved external symbol __imp__LogonUserA@24 
referenced in function _Java_Validate_takeInfo@24
Validate.dll : fatal error LNK1120: 1 unresolved externals

I have probably tried a thousand different ways to compile playing with the LIBPATH switch.

-link -LIBPATH:"C:\Program Files\Microsoft Visual Studio 8\VC\lib";"C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib"

and many others.

[Update] if i switch around the lib paths and put "\PlatformSDK\lib" before the "\VC\lib" switch i get this error:

LINK : fatal error LNK1104: cannot open file 'uuid.lib'

becuase it now cannot recognise the other libpath. Any idea? [/Update]

How do i declare multiple libpaths? is there something else causing this?

As always, thanks guys

+1  A: 

MSDN says that LogonUser is in Advapi32.lib. It looks like the problem is that you're not including Advapi32.lib. LIBPATH affects where the linker searches for libraries, not what libraries the linker searches for, and nowhere are you telling the linker to search for Advapi32.dll.

On Visual C++ 2008, you should be able to do include Advapi32.lib by going under Project, Properties, Configuration Properties, Linker, Additional Dependencies. I'm not sure about other versions.)

From the command line, you should be able to just list Advapi32.lib as an additional file to be linked. Try this:

cl -I"c:\Program files\Java\jdk1.5.0_07\include"
   -I"C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include"
   -I"c:\program files\java\jdk1.5.0_07\include\win32"
   -LD D:\JNI\%filename%.cpp -D:\JNI\Fe%filename%.dll -link
   -LIBPATH:"C:\Program Files\Microsoft Visual Studio 8\VC\lib"
   -LIBPATH:"C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib"
   Advapi32.lib
Josh Kelley
Advapi32.lib is located in my "C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib" folder wich i am trying to include. I think the problem has to do with the fact i need to declare multiple libpath's.
Petey B
do you know how to include Advapi32 in the command line?
Petey B
Worked like a charm, thanks a million
Petey B