First time user on Cheerp

Asked by Paul on 2019-03-13

Hi i'm trying to build this C++ code into JS but keep running into this problem:

fatal error:
      'stdio.h' file not found
#include <stdio.h>

It is missing all the libc library and if i were to copy all the necessary lib file them into the same folder i'm not having much luck as they are dependency on sys and those do a look outside of sys etc.. Am i doing something wrong?
Here is my command for the cmake:

cmake -DCMAKE_TOOLCHAIN_FILE=/opt/cheerp/share/cmake/Modules/CheerpToolchain.cmake ..

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
Cheerp Edit question
Assignee:
No assignee Edit question
Solved by:
Paul
Solved:
2019-03-14
Last query:
2019-03-14
Last reply:
2019-03-14

Are you on Linux, Windows or MacOS?

How did you install Cheerp? From source of from our packages?

Can you compile a simple hello world such as the one here: https://github.com/leaningtech/cheerp-meta/wiki/Cheerp-Tutorial#hello-world-wide-web-?

Paul (lynxpaul) said : #2

i'm on MacOS 10.13.6 (High Sierra)

Installed via https://launchpad.net/cheerp/+download with dmg package move the directory into /opt/cheerp/

I was able to compile and run the simple hello world with no issue

The problem is that Cheerp should be installed in /Applications/cheerp, not in /opt/cheerp on the Mac. If you use the standard DMG procedure of dragging and dropping the cheerp directory over the link it will just work.

Although Cheerp itself can run from any directory the cmake toolchain file needs to assume a specific path.

Please reinstall Cheerp in it's standard MacOS location /Applications/cheerp

Paul (lynxpaul) said : #4

So should I remove the opt/cheerp folder entirely.

I'll try that out.
Thanks

Paul (lynxpaul) said : #5

So i removed the opt/cheerp folder entirely and re-installed Cheerp inside Application (drag and dropped) and here is my new cmake command :

cmake -DCMAKE_TOOLCHAIN_FILE=/Applications/cheerp/share/cmake/Modules/CheerpToolchain.cmake ..

Still same error:

      'stdio.h' file not found
#include <stdio.h>

Can you compile the following test?

--------------------------------
#include <stdio.h>

void webMain()
{
        printf("stdio test\n");
}
------------------------------

/Applications/cheerp/bin/clang++ -target cheerp stdio.cpp -o stdio.js

Paul (lynxpaul) said : #7

Yes that worked with no issue.

Paul (lynxpaul) said : #8

Now i tried the same thing with cmake :

cmake_minimum_required(VERSION 2.8.9)
project (hello)
add_executable(hello hello.cpp)

cmake -DCMAKE_TOOLCHAIN_FILE=/Applications/cheerp/share/cmake/Modules/CheerpToolchain.cmake ..
make

and that worked too ...

So, is the problem fixed?

Paul (lynxpaul) said : #10

No sir it still doesn't work on my cmake project.
So i'm trying to minimize the cmake and tring to find the root cause of it ..

I noticed that i'm using

add_subdirectory
add_library
set_target_properties
configure_file
target_link_libraries
add_dependencies
include_directories

inside my cmake.
These shouldn't throw off Cheerp right? I was able to use emscripten with the same cmake and no problem creating an ASM.js file.

Yuri Iozzelli (yuri91) said : #11

Hi!
Can you run `make VERBOSE=1` ?
That will show the actual command used to invoke Cheerp (and the current working directory).
From there it should be easier to identify the problem.

Paul (lynxpaul) said : #12

Sweet thanks that was helpful
I was able to find that it fails on this command :

/Applications/cheerp/bin/clang++ -std=c++11 -o Utils.cpp.obj -c <pathToUtils>/Utils.cpp

In file included from <pathToUtils>/Utils.cpp:8:
In file included from <pathToUtils>/Utils.h:9:
<pathToUtils>/Node.h:9:10: fatal error:
      'stdio.h' file not found
#include <stdio.h>
         ^
1 error generated.

Paul (lynxpaul) said : #13

if i run the separate command alone i get the same error ie.
just running

/Applications/cheerp/bin/clang++ -std=c++11 -o Utils.cpp.obj -c <pathToUtils>/Utils.cpp

without the cmake.

Yuri Iozzelli (yuri91) said : #14

The problem seems to be a missing `-target cheerp` parameter.
Our toolchain files set this parameter inside the CMAKE_CXX_FLAGS_INIT and CMAKE_C_FLAGS_INIT variables.
Any chances that you are overwriting them?

Paul (lynxpaul) said : #15

Ahhhh your right!!!
Thanks so much Yuri Iozzelli (yuri91)
and also
Alessandro Pignotti (a-pignotti)

Yuri Iozzelli (yuri91) said : #16

You are welcome :)