Opened 7 months ago

Closed 7 months ago

Last modified 6 months ago

#3336 closed help (fixed)

Compiling/Running C with X11

Reported by: ass98av Owned by: pmcguire
Component: Other Keywords: C, X11, Mac, Xquartz
Cc: Platform: Other
UM Version:

Description

Hi Patrick,

Do you compile or run C programs?

I am stuck with something.

It is about getting Fred Oden’s code to work.

He uses X11, which of course is now obsolete. However, it still seems to be part of Anaconda2, but I am not sure how to run C under that.

I downloaded XQuartz yesterday thinking that would do the trick.

However,

When I run the makefile it says:

fatal error: 'X11/Xlib.h' file not found
#include <X11/Xlib.h>

perhaps this is simply a path problem.

I can only find one Xlib.h on my machine

/Library/Developer/?CommandLineTools/SDKs/MacOSX11.0.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11

perhaps it would be easiest if I sent the entire directory with files to dropbox for you to see?

This is a download from Fred’s link.

See below

Do you also have Mac OS Catalina?

I am using the latest gcc from homebrew.

All the best
Anne V

Attachments (1)

M2WC70.zip (165.3 KB) - added by pmcguire 7 months ago.

Download all attachments as: .zip

Change History (18)

Changed 7 months ago by pmcguire

comment:1 Changed 7 months ago by pmcguire

Hi Anne
Yes, I use Catalina. I was able to get it to compile.

Based upon this stackoverflow post https://stackoverflow.com/questions/55165296/macos-mojave-xlib-error-while-compiling-fatal-error-x11-xlib-h-file-not-fou, I did:

find /usr /opt -type d -name X11

and from the output of that, I therefore decided to change the makefile as follows:

#CFLAGS  := -I../util -Wall -O3
CFLAGS  := -I../util -I/opt/X11/include  -Wall -O3
#LDFLAGS := -lm -lX11
LDFLAGS := -L/opt/X11/lib -lm -lX11

Patrick

comment:2 Changed 7 months ago by pmcguire

Hi Patrick,

Good, success on your end.

When I type that command I get:

find: /usr/sbin/authserver: Permission denied
/opt/X11
/opt/X11/include/X11
/opt/X11/etc/X11
/opt/X11/lib/X11
/opt/X11/share/sgml/X11
/opt/X11/share/X11
/opt/anaconda3/include/X11
/opt/anaconda3/pkgs/tk-8.6.8-ha441bb4_0/include/X11
/opt/miniconda2/include/X11
/opt/miniconda2/pkgs/tk-8.6.8-ha441bb4_0/include/X11

that looks nothing like what you changed the CFLAGS and LDFLAGS to?

What do you suggest I change those flags to, based on the above?

I am not sure about the anaconda 3, I downloaded version 2, as I use Python v2.

(what did you get when you typed that command?)

Did you change anything else in the make file(s)?
Thank you!

Anne

comment:3 Changed 7 months ago by pmcguire

Hi Anne
For me, when I run that command, I get:
find /usr /opt -type d -name X11
find: /usr/sbin/authserver: Permission denied
/opt/X11
/opt/X11/include/X11
/opt/X11/etc/X11
/opt/X11/lib/X11
/opt/X11/share/sgml/X11
/opt/X11/share/X11

Normally, you need to tell the Makefile where to find the include files (in this case, X11/Xlib.h) and the libraries.
That's why I added the -I and -L strings to the makefiles as such.
I think for you, the string changes should be the same as for me.
Patrick

comment:4 Changed 7 months ago by pmcguire

Hi Patrick,

Thank you I will try and feed back. These string things mean very little to me, I will need to study up on C.

‘later

Anne

comment:5 Changed 7 months ago by pmcguire

Cool, it worked! 😊👍

But there is another makefile under the util directory

Did you change things there too?

Thanks

Anne

comment:6 Changed 7 months ago by pmcguire

I'm glad it worked!
No, I didn't change anything in the util directory, but maybe you need to, if you have similar errors making other code.
Patrick

comment:7 Changed 7 months ago by pmcguire

Hi Patrick,

Now for the running of it..

I can get it to run using

anneverhoef1@Annes-MacBook-Pro t_o_panama3 % ./test_panama
ERROR: Could not open X display.

But then I get the error on X display. This is something to do with X11?

Do I need to launch Xquartz first? I typed in Xquartz on the command line, but it crashed. I installed that via brew.

I am not really interested in the plots he makes, but not sure how to disable all of this .. ??

Cheers

Anne

comment:8 Changed 7 months ago by pmcguire

Hi Anne
My plots start appearing even if I haven't started Xquartz.
The plots look pretty cool.
But you can try starting Xquartz by double clicking on it in the Applications/!Utilities folder.
I have Xquartz version 2.7.11.
Patrick

comment:9 Changed 7 months ago by pmcguire

Hi Again,

I managed to launch X11 after all, and now it does not complain about x-display.

It now says:

Error reading file example_rainfall_PET.txt
anneverhoef1@Annes-MacBook-Pro t_o_panama3 %

That file is there, but it could be to do with the EOL character

I will persevere.
Anne

comment:10 Changed 7 months ago by pmcguire

MMm, this is strange. How did you install it?

Do you run it just from your zsh terminal command line? So not from the Xterm?

Cheers

Anne

comment:11 Changed 7 months ago by pmcguire

I don't remember how I installed Xquartz. I might have had to download it from their website.
I don't remember if I used brew or not.

Xquartz should normally should start automatically when it's needed. You might need to check your installation by typing xclock in your terminal window or something like that.

Patrick

comment:12 Changed 7 months ago by pmcguire

Hi Patrick,

I see, I will try this. But it seems to get stuck on this (line 763).

when I get the error: Error reading file example_rainfall_PET.txt

I don’t understand why this does not happen to you.

Does it set it to NULL initially?

No wonder it can’t open it?

      // Read input rainfall file.
      FILE*  rain_fptr      = NULL;
  
      if (NULL == (rain_fptr = fopen("example_rainfall_PET.txt", "r")))
        {
          printf("Error reading file example_rainfall_PET.txt \n");
          exit(1);
        }

Cheers

Anne

comment:13 Changed 7 months ago by pmcguire

Hi Patrick,

Just to let you know that it is running now. I decided to re-install !XQuartz again, this time from the package, not from brew.

This did the trick..

I am seeing the plots too now :-)

So you can close the ticket, and thank you very much!

Anne

comment:14 Changed 7 months ago by pmcguire

Hi Anne:
I am glad it's working!
Patrick

comment:15 Changed 7 months ago by pmcguire

  • Component changed from UM Model to Other
  • Owner changed from um_support to pmcguire
  • Status changed from new to accepted

comment:16 Changed 7 months ago by pmcguire

  • Resolution set to fixed
  • Status changed from accepted to closed

comment:17 Changed 6 months ago by pmcguire

  • Cc ass98av removed
  • Reporter changed from pmcguire to ass98av
Note: See TracTickets for help on using tickets.