0

I'm making the switch from windows to macOS and most seems to be going well. I will be producing terminal applications for my own use only. I can use Xcode IDE but its file system seems overly-complicated and I'd just prefer compiling from the terminal command line. Personal preference I guess.

I have created a program main.cpp that contains one function outside the "main" section of the program. It compiles and runs with just fine with g++ main1.cpp -o main1.app.

I separated the external function into its own 'externalfunction.cpp' file and left the prototype in the main program. g++ main2.cpp external function.cpp -o main2.app compiles and works just fine.

I moved the function prototype declaration to its own .h file ('jjdate.h'). and I removed the function prototype declaration from the main3.cpp file. and I added #include "jjdate.h" to the main3.cpp

All files are in the same directory ./cprograms

I moved to the ./cprograms directory (cd./cprograms)

I expected g++ main3.cpp external function.cpp -I jjdate.h to work. Not so.

I've tried multiple different arguments to the -I such "./cpgrograms/jjdate.h" and "./" with and without file name,

I've also tried eliminating the -I altogether.

Including the -I seems to come closest but I always get the following error

Here's the command line Jon--Kathys-MBP:cprograms jon$ g++ main3.cpp externalfunction.cpp -I "jjdate.h" -o main3.app

I get the same error no matter what I put in after the -I (ex. jjdate.h with or without quotes, with or without path etc.) All files are in the same directory.

main3.cpp:16:10: error: expected "FILENAME" or

include “jjdate.h”

I haven't included the code because the question is already long. The code works. But making a library file and ".h" file is not. I think I'm close.

Community
  • 1
  • 1
jjuhlin
  • 1
  • 1
  • You should put after `-I` either absolute path to the include folder or relative (to build work directory) path to the include folder, not the header file name. – user7860670 Nov 05 '17 at 21:58
  • 1
    It looks like you have fancy quotes in the line `#include “jjdate.h”`. Change them to `"`. – Mark Plotnick Nov 05 '17 at 23:01
  • regarding path after -I: I tried no path with or without a filename as possible options and I tried nothing at all since all files are in the same directory. The programs are in 'programs'. So I entered cd ./cprograms to change the working directory to the same directory that holds the files. Hence my initial try was nothing for the logic given. Then I tried ./. Then ./cprograms. The all three with the filename added with no quotes.The all three with the filename with quotes. Hence, from your comment, if all files are in the current working directory the relative path would be nothing or ./ ? – jjuhlin Nov 06 '17 at 00:26
  • regarding Mark's comment about fancy quotes. I see from your comment that there is a difference. But this is a new one for me. I have only recently changed from PC to Mac and perhaps my ignorance is related to that. There is only one double quote key on the keyboard. Have I been pranked? Or is there really a difference? – jjuhlin Nov 06 '17 at 00:31
  • Your text editor may be converting the quotes for you because it thinks you're writing a novel rather than a C++ program. Your text editor may have settings to prevent it from treating quotes this way. – Mark Plotnick Nov 06 '17 at 00:38

0 Answers0