Created a simple console application which imports functions exposed in the DLL and the DLL was created using c-shared option in golang. The go DLL depends on other DLL which was created using C++. The dependent DLL are placed in the correct path so console application is able to locate them while loading. "The application was unable to to start correctly(0x0000142)" error is seen while launching console application.
I tried it on Windows10 machine and tried to create executable program in go using cgo to add dependency on other DLL. The executable works fine but when the same is turned into DLL and then issue is while importing the DLL in C application.
Check DLL were created using following code
check.h
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) char* testing1(char* input);
__declspec(dllexport) char* testing2(char* input);
#ifdef __cplusplus
}
#endif
check.cpp
#include <cstdio>
#include <cstdlib>
#include <iostream>
#define DllExport __declspec(dllexport)
extern "C" __declspec(dllexport) char* testing1(char* input){
return input;
}
extern "C" __declspec(dllexport) char* testing2(char* input){
return input;
}
int main(int argc, char* argv[])
{
char* result = testing1("testing ");
std::cout<<"Result : "<< result<<std::endl;
}```
Go code for creating DLL which dependency on above created Check.DLL
package main
/*
#cgo LDFLAGS: -lCheck
#include <check.h>
#include <stdlib.h>
#include <string.h>
*/
import "C"
import "fmt"
//export AddTwoNums
func AddTwoNums(numone int, numtwo int) int {
return numone + numtwo
}
//export Validate
func Validate(args *C.char) *C.char {
str := C.GoString(args)
str = str + "-" + str
return C.CString(str)
}
func importFromClib1() {
str1 := "Testing1"
cstr := C.CString(str1)
result := C.testing1(cstr)
fmt.Println("Testing1 result : ", C.GoString(result))
}
func importFromClib2() {
str1 := "Testing2"
cstr := C.CString(str1)
result := C.testing2(cstr)
fmt.Println("Testing2 result : ", C.GoString(result))
}
func main() {
}
Expected the importing of function AddTwoNums and Validate should not cause any issue while running the console application. But the error mentioned in the problem is seen.