New to cgo - unable to include header

OS:- windows.
Go version :- 1.11

I have written a program which uses some functions in c header file. I am getting the below error.

Error:
#go build command-line-arguments: invalid flag in #cgo CFLAGS: Files/IBM/SQLLIB

Code:(sql.go)

package main

// #cgo CFLAGS: -I C:/Program Files/IBM/SQLLIB
// #cgo LDFLAGS:  -lsqllib
// #include "sqlcli1.h"
import "C"

import "fmt"

func main() {
	fmt.Println(C.SQL_BLOB)
}

The sqlcli1.h file is LOCATED in C:\Program Files\IBM\SQLLIB\include.
AND my code(sql.go) is LOCATED in C:\Go\programs

How to solve this Error
Thanks in Advance.

How to give the path from environmental variables

What is the use of -lsqllib that you used in LDFLAGS

When i place your code in my code it produced the following error.

C:\Users\rakhil\go\src\github.com\ibmdb\go_ibm_db>go run sql_check.go
# command-line-arguments
In file included from C:/Program Files/IBM/SQLLIB/include/sqlcli.h:989:0,
                 from C:/Program Files/IBM/SQLLIB/include/sqlcli1.h:45,
                 from .\sql_check.go:5:
C:/Program Files/IBM/SQLLIB/include/sqlext.h:1748:5: error: unknown type name '__in_ecount'
     __in_ecount(cchConnStrIn)
     ^
C:/Program Files/IBM/SQLLIB/include/sqlext.h:1751:5: error: unknown type name '__out_ecount_opt'
     __out_ecount_opt(cchConnStrOutMax)
     ^
C:/Program Files/IBM/SQLLIB/include/sqlext.h:1754:5: error: unknown type name '__out_opt'
     __out_opt
     ^
C:/Program Files/IBM/SQLLIB/include/sqlext.h:1865:5: error: unknown type name '__in_ecount'
     __in_ecount(cchConnStrIn)
     ^
C:/Program Files/IBM/SQLLIB/include/sqlext.h:1868:5: error: unknown type name '__out_ecount_opt'
     __out_ecount_opt(cchConnStrOutMax)
     ^
C:/Program Files/IBM/SQLLIB/include/sqlext.h:1871:5: error: unknown type name '__out_opt'
     __out_opt
     ^
C:/Program Files/IBM/SQLLIB/include/sqlext.h:1891:5: error: unknown type name '__in_ecount_opt'
     __in_ecount_opt(cchCatalogName)

specstrings.h file in sqllib/include?

I understood that it is not cgo problem. Can u know how to solve it @rot13

I checked it, The error was due to specstrings.h file in gcc. I resolved it.

Thanks @rot13

Line 4 means in the code right

Code:-
-lsqllib looks for sqllib folder in the LDFLAGS path.

We have to use it if we have more than one folder in the path

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.