Skip to content

Commit

Permalink
fix: library path added using tcc_add_library
Browse files Browse the repository at this point in the history
  • Loading branch information
jaromil committed Dec 2, 2024
1 parent ac8a97a commit 1f04ac6
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions src/cjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

/////////////
// from file.c
extern bool append_path(char **stored_path, const char *new_path);
extern bool prepend_path(char **stored_path, const char *new_path);
extern long file_size(const char *filename);
extern char* file_load(const char *filename);
extern char *load_stdin();
Expand Down Expand Up @@ -120,8 +118,6 @@ const char cli_help[] =
int main(int argc, char **argv) {
TCCState *TCC = NULL;
// const char *progname = "cjit";
char *stored_lib_paths = NULL;
char *stored_inc_paths = NULL;
char *tmpdir = NULL;
const char *default_main = "main";
char *entry = (char*)default_main;
Expand Down Expand Up @@ -183,14 +179,11 @@ int main(int argc, char **argv) {
exit(1);
}
} else if (c == 'L') { // library path
if(! append_path(&stored_lib_paths, opt.arg) ) {
_err("Error in lib path -L option argument");
tcc_delete(TCC);
exit(1);
}
if(!quiet)_err("lib path: %s",opt.arg);
tcc_add_library_path(TCC, opt.arg);
} else if (c == 'l') { // library link
if(!quiet)_err("lib: %s",opt.arg);
tcc_add_library(TCC, opt.arg);
tcc_add_library(TCC, opt.arg);
} else if (c == 'C') { // cflags compiler options
if(!quiet)_err("cflags: %s",opt.arg);
tcc_set_options(TCC, opt.arg);
Expand Down Expand Up @@ -240,22 +233,11 @@ int main(int argc, char **argv) {
_err("Error creating temp dir: %s",strerror(errno));
goto endgame;
}
tcc_set_lib_path(TCC,tmpdir); // TCC specific lib path

if(! prepend_path(&stored_lib_paths,tmpdir) ) {
_err("Error prepending tmpdir library path: %s",tmpdir);
goto endgame;
}
if(! prepend_path(&stored_inc_paths,tmpdir) ) {
_err("Error prepending tmpdir include path: %s",tmpdir);
goto endgame;
}

tcc_add_include_path(TCC, tmpdir);

// finally set paths
// _err("lib paths: %s",stored_lib_paths);
tcc_add_library_path(TCC, stored_lib_paths);
tcc_add_include_path(TCC, tmpdir);
tcc_add_library_path(TCC, tmpdir);
// tcc_set_lib_path(TCC,tmpdir); // this overrides all?

// set output in memory for just in time execution
tcc_set_output_type(TCC, TCC_OUTPUT_MEMORY);
Expand Down Expand Up @@ -353,8 +335,6 @@ int main(int argc, char **argv) {
endgame:
// free TCC
if(TCC) tcc_delete(TCC);
if(stored_inc_paths) free(stored_inc_paths);
if(stored_lib_paths) free(stored_lib_paths);
if(entry!=default_main) free(entry);
exit(res);
}

0 comments on commit 1f04ac6

Please sign in to comment.