Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation of example program on OS X #25

Closed
CNugteren opened this issue Aug 6, 2015 · 11 comments
Closed

Compilation of example program on OS X #25

CNugteren opened this issue Aug 6, 2015 · 11 comments
Labels

Comments

@CNugteren
Copy link

I am following the basis getting starting guide and am currently trying to compile the Susan program. Unfortunately, compilation fails on OS X (Darwin-14.4.0-x86_64-i386-64bit):

cnugteren$ ck compile program:cbench-automotive-susan --speed
***************************************************************************************
Current directory: /Users/cnugteren/CK/ctuning-programs/program/cbench-automotive-susan/tmp
***************************************************************************************
Resolving dependencies ...
***************************************************************************************
Compiler vars:
  XOPENME=
***************************************************************************************
Executing prepared batch file tmp-PzV7hE.sh ...
CK_CC  CK_OPT_SPEED CK_FLAGS_CREATE_OBJ CK_COMPILER_FLAGS_OBLIGATORY CK_FLAGS_DYNAMIC_BIN {CK_FLAG_PREFIX_INCLUDE}../ {CK_FLAG_PREFIX_VAR}XOPENME {CK_FLAG_PREFIX_INCLUDE}/Users/cnugteren/CK-TOOLS/lib-rtl-xopenme-0.3-gcc-local-macos-64/include  ../susan.c  {CK_FLAGS_OUTPUT}susan.o
./tmp-PzV7hE.sh: line 8: CK_CC: command not found
***************************************************************************************
Compilation time: 0.013 sec.; Object size: 0; MD5: 
Warning: compilation failed!

It seems that several variables starting with CK_ are not properly substituted, perhaps there is a missing $-sign? Or did I forget to do something, perhaps loading some environmental variables? Setting $CK_CC to for example Clang doesn't seem to help.

@gfursin
Copy link
Contributor

gfursin commented Aug 6, 2015

Sorry for those issues - I did not test CK on Mac OS and I assumed that the conventions/commands are the same as in Linux. However, seems like there are differences. I think the problem is in exporting variables:
before compiling programs, I check for CK environments with compilers. So for MacOS, by default, I added entry "env:compiler-gcc-local-macos-h64-t64" (part of my fix yesterday). You can find this entry via:

ck find env:compiler-gcc-local-macos-h64-t64

There you will see file "env.sh" - it is executed just before compilation and it's the one that sets
up CK_CC, etc.

It uses bash and relies on two things:

#! /bin/bash
if [ "$1" != "1" ]; then if [ "$CK_ENV_COMPILER_GCC_SET" == "1" ]; then return; fi; fi

Above line checks if the script was already called to avoid calling it again (unless forced by CK) -
maybe there is an issue there and it doesn't go further.

Otherwise, I also use:

export CK_AR=ar
export CK_ASM_EXT=.s
export CK_CC=gcc
export CK_COMPILER_FLAGS_OBLIGATORY=

Maybe export doesn't properly on MacOS and something else is needed?..

Can you please just try to run it like that:
. ./env.sh ; echo $CK_CC
If it doesn't work, then the problem is in exports or first line ...

Thanks!

@gfursin gfursin added the bug label Aug 6, 2015
@CNugteren
Copy link
Author

Setting the environment works fine:

compiler-gcc-local-macos-h64-t64$ . ./env.sh ; echo $CK_CC
gcc
compiler-gcc-local-macos-h64-t64$ $CK_CC --version
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)

(note that running gcc or g++ actually runs Clang on OS X)

I believe that the problem is that the other script doesn't actually substitute CK_CC with $CK_CC (and so on): somehow the dollar signs are removed.

@gfursin
Copy link
Contributor

gfursin commented Aug 6, 2015

Strange. May I ask you to compile program with the following flag:

ck compile program:cbench-automotive-susan --speed --skip_clean_after

It should keep all temporary files. You can find them in tmp directory of the entry:

ck find program:cbench-automotive-susan

There should be one or more files tmp-XYZ.sh

Can you please print them here (or at least one where there is CK_CC)?

Thanks!

@gfursin
Copy link
Contributor

gfursin commented Aug 6, 2015

Oh, I fixed that - stupid mistake - I just did not add environment var description to MasOS entry in CK.
I just fixed that. You can update CK is usual with:

ck pull all

Can you please try to compile program again (I am now concerned about GCC -> LLVM substitution - hope there will be no new problems with calling conventions) ...

You can find MacOs description here:

ck find os:macos-64

There is a file .cm/meta.json that I use to describe various OS parameters needed for CK - this allows me to support Android, remote SSH, Windows, etc (you can also view it directly in console via ck load os:macos-64). You can see other OS via:

ck list os

@CNugteren
Copy link
Author

Thanks! Looks like compilation goes fine, but now there are linker warnings:

Executing prepared batch file tmp-XLctMv.sh ...
gcc  -O3 -c   -I../ -DXOPENME -I/Users/cnugteren/CK-TOOLS/lib-rtl-xopenme-0.3-gcc-local-macos-64/include  ../susan.c  -o susan.o
../susan.c:688:9: warning: implicit conversion from 'double' to 'TOTAL_TYPE' (aka 'int') changes value from 0.1 to 0 [-Wliteral-conversion]
  total=0.1; /* test for total's type */
       ~^~~
1 warning generated.
gcc    susan.o  -o a.out    -L/Users/cnugteren/CK-TOOLS/lib-rtl-xopenme-0.3-gcc-local-macos-64/lib -lrtlxopenme -lm
ld: warning: directory not found for option '-LCK_ENV_LIB_RTL_XOPENME_LIB'
ld: warning: directory not found for option '-LLIBRARY_PATH'
./tmp-XLctMv.sh: line 15: objdump: command not found
./tmp-XLctMv.sh: line 17: md5sum: command not found
***************************************************************************************
Compilation time: 1.139 sec.; Object size: 0; MD5: 
Warning: compilation failed!

The issues with objdump and md5sum can probably be solved by installing the software packages (e.g. using home-brew). Alternatively for maximum compatibility, md5sum can be replaced by the system's md5 -r and objdump can be replaced by otool -tV <executable> (to disassemble). Let me know if you need more information.

I am not sure if this is relevant, but OS X uses $DYLD_LIBRARY_PATH instead of $LD_LIBRARY_PATH.

@gfursin
Copy link
Contributor

gfursin commented Aug 6, 2015

I think I fixed all above issues:

As usual, do not forget to do

ck pull all

  • problem with -L... is because you install XOPENME library while there was still a problem with $ on MACOS. So you need to reinstall it. The easiest way is probably to find a given entry in CK:

ck show env --tags=xopenme

Then find related ENV UID (on the left) - normally you should have only 1 entry ...
And then remove this CK environment entry:

ck rm env:

for example: ck rm env:593df795f48cfbb5

Now you can reinstall xopenme and hopefully it should now have $ ...

  • I fixed objdump as you suggested. It is in the env.sh of the following GCC desriptions:

    ck find env:-macos-

  • I also fixed md5sum as you suggested - I moved it to the OS description (key "md5sum"):

    ck load os:macos-64

Please, tell me if it will work! Thanks!!!

By the way, note that my idea of CK was to make it extensible by the community aka research Wikipedia, i.e. users can add/unify descriptions/modules just like we do above.
So, if we will manage to add support for MAC OS without breaking the whole framework,
it should support such agile approach ;) ...

@CNugteren
Copy link
Author

Works as advertised, thanks!

@gfursin
Copy link
Contributor

gfursin commented Aug 6, 2015

Great! By the way, before closing this ticket, do you mind to remove again the env of the XOPENME as describe above and then try to install it automatically, i.e. when you compile program?
I am curious if above fixes fixed the autoinstall problem too?..
Thanks again!

@CNugteren
Copy link
Author

No, that doesn't solve it:

WARNING: environment was not found using tags="lib,xopenme" and setup={"target_os_bits": "64", "host_os_uoa": "macos-64", "target_os_uoa": "macos-64"}
  Would you like to search and install package with these tags automatically (Y/n)? Y
CK error: environment was not found using tags="lib,xopenme" and setup={"target_os_bits": "64", "host_os_uoa": "macos-64", "target_os_uoa": "macos-64"}!

Is there a way to get it more verbose?

@gfursin
Copy link
Contributor

gfursin commented Aug 6, 2015

Sure. I need to check first what happens. Will try to reproduce this on my machine. Will tell you if I manage to sort it out ...

@gfursin
Copy link
Contributor

gfursin commented Aug 6, 2015

I will close this ticket and will check it in ticket #24 ...

@gfursin gfursin closed this as completed Aug 6, 2015
gfursin added a commit that referenced this issue Oct 29, 2024
CM/CMX v3.2.8: fixed a few tests (#1340)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants