-2

I need some help.

I worked on a C project locally and it ran perfect with no issues at all. Then I moved my whole project files to a linux server (using Bitwise) and ran it using the following command:

gcc -g -std=c99 -Wall -pedantic-errors -Werror -DNDEBUG main.c map.c map.h utilities.c utilities.h election.c election.h extended_map.c extended_map.h test_utilities.h -o outmap 

and again everything worked as expected.

Now, I want to replace my version of test_utilities.h with the version saved on that server, so I opened main.c (which is the only file to include test_utilities.h and replaced:

#include "test_utilities.h" 

with

#include "~mtm/public/1920b/ex1/test_utilities.h" 

But the terminal shows me the following error:

gcc: error: test_utilities.h: No such file or directory -bash-4.2$ 

As suggested I changed it to

gcc -g -std=c99 -Wall -pedantic-errors -Werror -DNDEBUG main.c map.c map.h utilities.c utilities.h election.c election.h extended_map.c extended_map.h test_utilities.h -o outmap -I ~mtm/public/1920b/ex1/ 

But still I get the following:

gcc: error: test_utilities.h: No such file or directory

update2: (I was requested to remove .h files so now I got)

gcc -g -std=c99 -Wall -pedantic-errors -Werror -DNDEBUG main.c map.c utilities.c election.c extended_map.c -o outmap 
3
  • Does it work if you manually specify the full path to your home directory instead of ~mtm? Commented May 8, 2020 at 19:13
  • But that's the root, what do u mean? Commented May 8, 2020 at 19:15
  • 3
    It is unacceptable here to deface your post once it's been answered according to the site's Terms of Service. Please do not do so again. If you continue to deface your posts as you've done twice now, I'm going to flag them for a moderator's attention and you may end up suspended, which would mean you are unable to ask questions here in the future. Commented May 9, 2020 at 0:29

1 Answer 1

2

Writing ~mtm to refer to the home directory of user mtm is a shortcut that your shell understands. It isn't something that the C preprocessor understands. So you'll have to spell it out as /home/mtm (or wherever mtm's home directory is located) instead of ~mtm.

That said, a better way would be to just leave it as "test_utilities.h" and instead adjust the include path of the compiler (specified via -I when invoking the compiler) to include ~mtm/public/1920b/ex1/.

You also shouldn't specfiy test_utilities.h as an argument to the compiler. In fact none of the header files should be passed as arguments to the compiler.

Sign up to request clarification or add additional context in comments.

13 Comments

@smith_97 Leave the include as #include "test_utilities.h" and add the option -I ~mtm/public/1920b/ex1/ when you call gcc. With that option you can include any files from the directory by just specifying their names.
But not all of my files are under that directory... some of them under the current one kindly read my last update in the main quesiton
@smith_97 -I adds include directories, it doesn't override existing ones. That is, adding a directory via -I won't make includes from other directories (including the current directory) stop working.
@smith_97 About you still getting that error: The error you're getting is actually about you specifying test_utilities.h on the command line. It doesn't currently even get to the error at the #include. As mentioned in my last paragraph, you shouldn't be listing header files on the command line at all.
Could you add full example, what do u mean not to list header files? I need to compile them
|