Cygwin C program not accepting command line arguments -


i writing program in c uses sdl2 on cygwin. problem having argc 1, when command line contain other arguments.

this bit difficult replicate can't post code program, can include main source here make sure main function correct.

my question if there known reason why argc 1 , not include other command line arguments (weather intentionally or side effect using sdl2 etc)?

this code i'm using:

#include <stdlib.h> #include <stdio.h> #include "config.h" #include <string.h>  #ifdef signal_avail #include <signal.h> #endif  #include "process.h" #include "nvconsole.h" #include "stringutils.h"  #include "nova.h"  struct novacontext_s *context;      // nova system context  #ifdef signal_avail  // #### signal handler #### void sig_handler(int signo) {     if (signo == sigint)     {            nvconsole_print(nvinfo,"terminated user");                nvconsole_println(nvinfo,"");         nova_cleanup(context);               exit(0);     }    }  #endif  void init() { #ifdef signal_avail     if (signal(sigint, sig_handler) == sig_err)     {         nvconsole_println(nverror,"[main] can't catch sigint");         exit(1);     }        if (signal(sigquit, sig_handler) == sig_err)     {         nvconsole_println(nverror,"[main] can't catch sigquit");         exit(1);     } #endif }  int main(int argc, char* argv[]) {  for(int i=0;i<argc;i++) printf("%d %s\n",i,argv[i]);      init();      context = nova_createcontext();      nova_init(context);      nova_loop(context,0);     nova_cleanup(context);      return 0; } 

although code doesn't directly use sdl, being linked , used other parts of included code. below output this:

$ ./bin/nova 0 f:\dev\nova\bin\nova.exe  $ ./bin/nova hello 0 f:\dev\nova\bin\nova.exe 

i've included makefile below:

arch = $(shell uname)  cxx=gcc -std=c99   ifeq ($(arch), darwin)     sdlflags = `/usr/local/bin/sdl2-config --cflags`     sdllibs = `/usr/local/bin/sdl2-config --libs` else     sdlflags = `sdl2-config --cflags`     sdllibs = `sdl2-config --libs` endif  #opt= -o2 -s -d_gnu_source opt= -o2 -d_gnu_source  include=-i. -i.. -isrc/nova -isrc/nvscript -isrc/common -isrc/headers -isrc/modules -isrc/search  #warn=-werror cwd=$(shell pwd)  #cxxflags= $(opt) $(include) $(sdlflags) $(warn) -fpic cxxflags= $(opt) $(include) $(sdlflags) $(warn)  libs= -lm $(sdllibs) -ldl  ld=$(cxx) $(opt)  #####################################################  libnvscript_api_version = 1.0.0  #####################################################  comp   = nova \          nvdata \          nvconsole \          nvdatastore \          nvconfig \          nvevent \          rule_clock \          rule_nvs comp_h = nova.h \          nvdata.h \          nvconsole.h \          nvdatastore.h \          nvconfig.h \          nvevent.h \          rule_clock.h \          rule_nvs.h comp_headers := $(addprefix src/nova/, $(comp_h) ) comp_objs    := $(addprefix objs/, $(comp:=.o) ) comp_lib     := libs/libnova.a  #####################################################  nvscript   = nvscript \              nvscriptcore \              nvscriptresult \              nvscriptlist \              nvscriptstring \              nvscriptfile \              nvscriptnet \              nvscriptprocess \              nvscriptdebug \              nvscriptexec \              nvscriptmath nvscript_h = nvscript.h \              nvscriptcore.h \              nvscriptresult.h \              nvscriptlist.h \              nvscriptstring.h \              nvscriptfile.h \              nvscriptnet.h \              nvscriptprocess.h \              nvscriptdebug.h \              nvscriptexec.h \              nvscriptmath.h nvscript_headers := $(addprefix src/nvscript/, $(nvscript_h) ) nvscript_objs    := $(addprefix objs/, $(nvscript:=.o) ) nvscript_lib     := libs/libnvscript-$(libnvscript_api_version).a  #####################################################  common   = stringutils \            fileutils \            wildcard \            intarray \            floatarray \            chararray \            stringarray \            uchararray \            boolarray \            voidarray \            base64 \            sha1 \            scramble \            lfp \            x86_intmem \            x86_console \            x86_file \            x86_timer \            x86_net \            x86_process \            x86_rtc \            x86_keys \            sdl_video \            sdl_input common_h = stringutils.h \            fileutils.h \            mallocdebug.h \            wildcard.h \            intarray.h \            floatarray.h \            chararray.h \            stringarray.h \            uchararray.h \            boolarray.h \            base64.h \            voidarray.h \            sha1.h \            scramble.h \            lfp.h \            x86_intmem.h \            x86_console.h \            x86_file.h \            x86_timer.h \            x86_net.h \            x86_process.h \            x86_rtc.h \            x86_keys.h \            sdl_video.h \            sdl_input.h common_headers := $(addprefix src/common/, $(common_h) ) common_objs    := $(addprefix objs/, $(common:=.o) ) common_lib     := libs/libmlcommon.a  #####################################################  search = search searchitem search_h = search.h searchitem.h search_headers := $(addprefix src/search/, $(search_h) ) search_objs    := $(addprefix objs/search/, $(search:=.o) ) search_lib     := libs/libsearch.a  #####################################################  modules   = ui statusbar welcome context netmsg modules_h = ui.h statusbar.h welcome.h context.h netmsg.h modules_headers := $(addprefix src/modules/, $(modules_h) ) modules_objs    := $(addprefix objs/modules/, $(modules:=.o) ) modules_dsos    := $(addprefix modules/, $(modules:=.so) )  #####################################################  output = main output_objs  := $(addprefix objs/, $(output:=.o) ) output_binary = bin/nova  nvsoutput = nvs nvsoutput_objs  := $(addprefix objs/, $(nvsoutput:=.o) ) nvsoutput_binary = bin/nvs  nvstestoutput = nvstest nvstestoutput_objs  := $(addprefix objs/, $(nvstestoutput:=.o) ) nvstestoutput_binary = bin/nvstest  searchoutput = search searchoutput_objs  := $(addprefix objs/, $(searchoutput:=.o) ) searchoutput_binary = bin/search  #####################################################  default: $(comp_lib) $(nvscript_lib) $(common_lib) $(search_lib) $(output_binary) $(nvsoutput_binary) $(nvstestoutput_binary) $(searchoutput_binary) modules: $(modules_objs) $(modules_dsos) nova: $(comp_lib) $(nvscript_lib) $(common_lib) $(output_binary) nvs: $(nvscript_lib) $(common_lib) $(nvsoutput_binary) $(nvstestoutput_binary)  #################### components #####################  objs/%.o: src/nova/%.c $(comp_headers)     @echo "compiling $<"     @$(cxx) $(cxxflags) -o $@ -c $<  $(comp_lib): $(comp_objs)     @echo "building nova library ($(comp_lib))"     @ar rcs $(comp_lib) $(comp_objs)  ##################### nvscript ######################  objs/%.o: src/nvscript/%.c $(nvscript_headers)     @echo "compiling $<"     @$(cxx) $(cxxflags) -o $@ -c $<  $(nvscript_lib): $(nvscript_objs)     @echo "building nvscript library ($(nvscript_lib))"     @ar rcs $(nvscript_lib) $(nvscript_objs)  #################### common #####################  objs/%.o: src/common/%.c $(common_headers)     @echo "compiling $<"     @$(cxx) $(cxxflags) -o $@ -c $<  $(common_lib): $(common_objs)     @echo "building mlcommon library ($(common_lib))"     @ar rcs $(common_lib) $(common_objs)  ################## modules #####################  # compile plugin , link shared library  objs/modules/%.o: src/modules/%.c $(modules_headers)     @echo "compiling module \"$*\""     @$(cxx) $(cxxflags) -o $@ -c $<  modules/%.so: objs/modules/%.o $(modules_headers)     @echo "linking module \"$*\""        @$(cxx) -shared -o $@  $(comp_objs) $(nvscript_objs) $(common_objs) $(libs) $<  #################### search #####################  objs/search/%.o: src/search/%.c $(search_headers)     @echo "compiling $<"     @$(cxx) $(cxxflags) -o $@ -c $<  $(search_lib): $(search_objs)     @echo "building search library ($(search_lib))"     @ar rcs $(search_lib) $(search_objs)  ###################### output #######################  objs/main.o: src/main/nova.c $(comp_headers) $(nvscript_headers) $(common_headers)     @echo "building binary ($<)"         @$(cxx) $(cxxflags) -o $@ -c $<  objs/nvs.o: src/main/nvs.c $(nvscript_headers) $(common_headers)     @echo "building binary ($<)"     @$(cxx) $(cxxflags) -o $@ -c $<  objs/nvstest.o: src/main/nvstest.c $(nvscript_headers) $(common_headers)     @echo "building binary ($<)"     @$(cxx) $(cxxflags) -o $@ -c $<  objs/search.o: src/main/search.c $(search_headers) $(common_headers)     @echo "building binary ($<)"     @$(cxx) $(cxxflags) -o $@ -c $<   $(output_binary): $(output_objs) $(comp_lib) $(nvscript_lib) $(common_lib)     @echo "linking $@"     @$(cxx) -o $@ $(output_objs) $(comp_objs) $(nvscript_objs) $(common_objs) $(libs)  $(nvsoutput_binary): $(nvsoutput_objs) $(nvscript_lib) $(common_lib)     @echo "linking $@"     @$(cxx) -o $@ $(nvsoutput_objs) $(nvscript_objs) $(common_objs) $(libs)  $(nvstestoutput_binary): $(nvstestoutput_objs) $(nvscript_lib) $(common_lib)     @echo "linking $@"     @$(cxx) -o $@ $(nvstestoutput_objs) $(nvscript_objs) $(common_objs) $(libs)  $(searchoutput_binary): $(searchoutput_objs) $(search_lib) $(common_lib)     @echo "linking $@"     @$(cxx) -o $@ $(searchoutput_objs) $(search_objs) $(common_objs) $(libs)  #####################################################  install:         ./install.sh  uninstall:       ./uninstall.sh  clean:     rm -f objs/*.o objs/modules/*.o objs/search/*.o */*.so */*.a modules/*.so libs/*.a $(output_binary).exe $(output_binary) $(nvsoutput_binary).exe $(nvsoutput_binary) $(nvstestoutput_binary).exe $(nvstestoutput_binary) $(searchoutput_binary) $(searchoutput_binary).exe 

i've written small test:

#include <stdlib.h> #include <stdio.h>   int main(int argc, char* argv[]) {     for(int i=0;i<argc;i++) printf("%d %s\n",i,argv[i]);  } 

and it's not surprising work , displays arguments, expect.

$ ./test hello 0 ./test 1 hello 

it's worth noting path argv[0] seems different in both examples, first (where it's not working) shows looks windows path, while second example (which work) showing linux looking path. indicate anything?

i think argc required here (not argv)

for(int i=0;i<argc;i++) printf("%d %s\n",i,argv[i]); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -