BOINC / boinc

Open-source software for volunteer computing and grid computing.
https://boinc.berkeley.edu
GNU Lesser General Public License v3.0
1.96k stars 440 forks source link

mac build + unix makefiles #3166

Open JamesMolson opened 5 years ago

JamesMolson commented 5 years ago

Before @CharlieFenton et al say, I know this is not the supported method.

Some notes on the suggested xcode method, it does not build boinc_api_fortran.o and I would prefer to use gcc since our work needs a fortran compiler, and also we can use the same compiler across all platforms. Note - we only build the core libraries and not the client, etc.

Problem 1:

  OBJC     libboinc_graphics2_la-macglutfix.lo
macglutfix.m:34:9: fatal error: 'MultiGPUMig.h' file not found
#import "MultiGPUMig.h"
        ^~~~~~~~~~~~~~~
1 error generated. 

Fixed by running the api folder:

mig  -header MultiGPUMig.h -sheader MultiGPUMigServer.h MultiGPUMig.defs

Problem 2:

  CXX      libboinc_la-procinfo_mac.lo
procinfo_mac.cpp: In function 'int procinfo_setup(PROC_MAP&)':
procinfo_mac.cpp:125:14: error: 'strchr' was not declared in this scope
  125 |         lf = strchr(p.command, '\n');
      |              ^~~~~~
procinfo_mac.cpp:37:1: note: 'strchr' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
   36 | #include "mac_branding.h"
  +++ |+#include <cstring>
   37 | 
procinfo_mac.cpp:130:42: error: 'strcasestr' was not declared in this scope
  130 |         p.is_boinc_app = (p.id == pid || strcasestr(p.command, "boinc"));
      |                                          ^~~~~~~~~~
make[2]: *** [libboinc_la-procinfo_mac.lo] Error 1

Fixed by including the above mentioned header.

Problem 3:

  CXX      libboinc_la-mac_spawn.lo
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGContext.h:21,
                 from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBitmapContext.h:9,
                 from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h:11,
                 from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/ApplicationServices.framework/Headers/ApplicationServices.h:35,
                 from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:24,
                 from mac/mac_spawn.cpp:23:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPath.h:391:15: error: expected unqualified-id before '^' token
  391 | typedef void (^CGPathApplyBlock)(const CGPathElement * element);
      |               ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPath.h:391:15: error: expected ')' before '^' token
  391 | typedef void (^CGPathApplyBlock)(const CGPathElement * element);
      |              ~^
      |               )

and so on.

The problem here is that a .cpp file is including Carbon.h which is an objective C header. This is the case in a few of the mac files - they look like c++ but are actually objective c++, and the simple fix is to just rename them from .cpp to .mm, then everything is happy. A small libtool fix is also required.

Problem 4: The makefile does not build mac/mac_branding.cpp Adding this to the Makefile.am fixes the linking issues one will obtain.

In general this is just a series of trivial fixes for which I can make a pull request, with the only question here being if I can rename a few .cpp files to .mm?

CharlieFenton commented 5 years ago

To the best of my knowledge carbon.h is not an objective C file, but I will confirm when I get home from my trip. If it were, the official build method would not work. The make files have not been updated in years for Mac builds so I would expect many issues trying to use them.

Charlie Fenton Sent from my iPhone

On May 28, 2019, at 4:40 AM, James Molson notifications@github.com wrote:

Before @CharlieFenton et al say, I know this is not the supported method.

Some notes on the suggested xcode method, it does not build boinc_api_fortran.o and I would prefer to use gcc since our work needs a fortran compiler, and also we can use the same compiler across all platforms. Note - we only build the core libraries and not the client, etc.

Problem 1:

OBJC libboinc_graphics2_la-macglutfix.lo macglutfix.m:34:9: fatal error: 'MultiGPUMig.h' file not found

import "MultiGPUMig.h"

    ^~~~~~~~~~~~~~~

1 error generated. Fixed by running the api folder:

mig -header MultiGPUMig.h -sheader MultiGPUMigServer.h MultiGPUMig.defs Problem 2:

CXX libboinc_la-procinfo_mac.lo procinfo_mac.cpp: In function 'int procinfo_setup(PROC_MAP&)': procinfo_mac.cpp:125:14: error: 'strchr' was not declared in this scope 125 | lf = strchr(p.command, '\n'); | ^~ procinfo_mac.cpp:37:1: note: 'strchr' is defined in header ''; did you forget to '#include '? 36 | #include "mac_branding.h" +++ |+#include 37 | procinfo_mac.cpp:130:42: error: 'strcasestr' was not declared in this scope 130 | p.is_boinc_app = (p.id == pid || strcasestr(p.command, "boinc")); | ^~~~~~ make[2]: *** [libboinc_la-procinfo_mac.lo] Error 1 Fixed by including the above mentioned header.

Problem 3:

CXX libboinc_la-mac_spawn.lo In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGContext.h:21, from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBitmapContext.h:9, from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h:11, from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/ApplicationServices.framework/Headers/ApplicationServices.h:35, from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:24, from mac/mac_spawn.cpp:23: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPath.h:391:15: error: expected unqualified-id before '^' token 391 | typedef void (^CGPathApplyBlock)(const CGPathElement element); | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPath.h:391:15: error: expected ')' before '^' token 391 | typedef void (^CGPathApplyBlock)(const CGPathElement element); | ~^ | ) and so on.

The problem here is that a .cpp file is including Carbon.h which is an objective C header. This is the case in a few of the mac files - they look like c++ but are actually objective c++, and the simple fix is to just rename them from .cpp to .mm, then everything is happy. A small libtool fix is also required.

Problem 4: The makefile does not build mac/mac_branding.cpp Adding this to the Makefile.am fixes the linking issues one will obtain.

In general this is just a series of trivial fixes for which I can make a pull request, with the only question here being if I can rename a few .cpp files to .mm?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

JamesMolson commented 5 years ago

It isn't carbon.h itself, it is all the other headers several layers down that are the issue - you end up in CoreGraphics.

It is the "^" in the following:

typedef void (^CGPathApplyBlock)(const CGPathElement * element);

as one of many possible examples.

The apple compilers eat this up by default, so the official build method works fine. gcc needs to be told to enable objc (and then it works).

CharlieFenton commented 5 years ago

From your example for problem 3, it looks like the issue is not that it is an objective-C file, but that the code uses an Apple-Clang specific extension to the C language which Apple calls blocks as described in this article. Given that this construct is an extension to Apple-Clang and that it is applicable to C, C++ and Objective-C (according to that article), I am surprised that renaming the .cpp files to .mm allows GCC to understand the construct. (I assume you have actually tried that and it works.)

I really dislike the idea of renaming the files for several reasons. First, the files you wish to rename do not themselves contain any objective-C code, and neither does carbon.h or any of its embedded headers. Second, this may cause headaches for everyone else who has been building the libraries using these files, as the Xcode project (or any custom make files they have created) will need to be updated to reflect the changes. Third, when you rename files, finding past changes (e.g., "blame") might be made more difficult.

Could you do the following?

lfield commented 5 years ago

Third, when you rename files, finding past changes (e.g., "blame") might be made more difficult.

Renaming files in git will preserve the history.

CharlieFenton commented 5 years ago

Here is another possible approach I would be comfortable with. The carbon.h header brings in many of the commonly needed standard headers. You could probably remove the #include <Carbon/Carbon.h> and instead add just those lower-level headers that are actually needed in each of these *.cpp files. If you decide to do this, I suggest adding a comment saying something like this:

// Don't include carbon.h because it causes problems when using the GNU compiler to build project applications

If you want to implement this approach, push your updated files to your feature branch and also update the make files (without boinc_api_fortran.cpp), and I'll merge them into master after confirming that the standard builds (using BuildMacBOINC.sh script) still work properly.

JamesMolson commented 5 years ago

@CharlieFenton you are correct, I just jumped to come conclusions after minimal reading :)

For some reason it compiled with gcc as objc, but yes, it is not objc. I'll just abandon building with gcc here.

Building with clang, everything works with some minor makefile changes. I'll make a PR soon.

Germano0 commented 5 years ago

You may want to give a look to this code I have written, and how I let GCC compile the C code I included in C++ BOINC client code