私はそれを愛したと思います。あなたは正しかった。問題は、私が使用していたincludeメソッドにありました。cコードにtcl.h、tclDecls.h、tclPlatDecls.hのファイルが含まれていますが、これらのファイルはパス/ usr / includeに存在していなかったため、これらのファイルをそのディレクトリにコピーしていました。これは適切ではなかった可能性があります。する方法。最後に、これらのファイルを/ usr / includeにコピーせず、コンパイル中にインクルードパスを指定しました。実行可能ファイルを作成しましたが、ターミナルで適切な結果が得られています。ご協力いただきありがとうございます。
これが私が使用している正確なcコードです:
#include <tcl.h>
#include <tclDecls.h>
#include <tclPlatDecls.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char **argv) {
Tcl_Interp *interp;
int code;
char *result;
printf("inside main function \n");
// Tcl_InitStubs(interp, "8.5", 0);
Tcl_FindExecutable(argv[0]);
interp = Tcl_CreateInterp();
code = Tcl_Eval(interp, "source simple_addition.tcl; add_two_nos");
/* Retrieve the result... */
result = Tcl_GetString(Tcl_GetObjResult(interp));
/* Check for error! If an error, message is result. */
if (code == TCL_ERROR) {
fprintf(stderr, "ERROR in script: %s\n", result);
exit(1);
}
/* Print (normal) result if non-empty; we'll skip handling encodings for now */
if (strlen(result)) {
printf("%s\n", result);
}
/* Clean up */
Tcl_DeleteInterp(interp);
exit(0);
}
そして、このコードをコンパイルし、実行可能ファイルを生成するために、私は以下のコマンドを使用しています:
gcc simple_addition_wrapper_new.c -I/usr/include/tcl8.5/ -ltcl8.5 -o simple_addition_op
simple_addition_opファイルを実行しましたが、適切な結果が得られました。
inside main function
c is 30 .......
DonalFellowsとJohannesに感謝します