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

".h" files are not found for dependencies #10971

Open
pb-cdunn opened this issue Apr 5, 2019 · 7 comments
Open

".h" files are not found for dependencies #10971

pb-cdunn opened this issue Apr 5, 2019 · 7 comments

Comments

@pb-cdunn
Copy link
Contributor

pb-cdunn commented Apr 5, 2019

When I build/install a particular module, everything is fine. I have a hybrid package, with .nim, .c, and .h files, installed as both a library and as binaries. That works.

The problem comes when I try to use it from another package.

% nimble install --nimbleDir:$N --verbose -y
...
        ... gcc -c  -w -g3 -O0 -O3 -fno-strict-aliasing  -I/mnt/software/n/nim/0.19.9/Nim/lib -I/localdisk/scratch/cdunn/repo/nim-falcon/src/falcon -o /home/UNIXHOME/cdunn/.cache/nim/example_r/DBX.c.o /localdisk/scratch/cdunn/repo/nim-falcon/nimbleDir/pkgs/daligner-0.0.0/daligner/DBX.c

# good!

        ... gcc -c  -w -g3 -O0 -O3 -fno-strict-aliasing  -I/mnt/software/n/nim/0.19.9/Nim/lib -I/localdisk/scratch/cdunn/repo/nim-falcon/src/falcon -o /home/UNIXHOME/cdunn/.cache/nim/example_r/daligner_dbx.c.o /home/UNIXHOME/cdunn/.cache/nim/example_r/daligner_dbx.c

        ... Error: execution of an external compiler program 'gcc -c  -w -g3 -O0 -O3 -fno-strict-aliasing  -I/mnt/software/n/nim/0.19.9/Nim/lib -I/localdisk/scratch/cdunn/repo/nim-falcon/src/falcon -o /home/UNIXHOME/cdunn/.cache/nim/example_r/daligner_dbx.c.o /home/UNIXHOME/cdunn/.cache/nim/example_r/daligner_dbx.c' failed with exit code: 1
        ... /home/UNIXHOME/cdunn/.cache/nim/example_r/daligner_dbx.c:10:17: fatal error: DBX.h: No such file or directory
        ...  #include "DBX.h"
        ...                  ^

Apparently, Nim fails to copy the *.h files into the compilation directory -- for dependencies only. The C code DB.c compiles fine because in C, #include "foo.h" looks in the directory of the source-file. But the wrapper daligner_dbx.c, from dbx.nim (which has {.compile: "DBX.c".}).

See the problem?

Again, when I build the package that has the .h files, everything works, but that's because Nim automatically adds -I for the current package, e.g.:

gcc -c  -w -g3 -O0 -O3 -fno-strict-aliasing  -I/mnt/software/n/nim/0.19.9/Nim/lib -I/localdisk/scratch/cdunn/repo/nim-falcon/repos/nim-DALIGNER/src/daligner -o /home/UNIXHOME/cdunn/.cache/nim/LA4Falcon_r/daligner_dbx.c.o /home/UNIXHOME/cdunn/.cache/nim/LA4Falcon_r/daligner_dbx.c

See -I/localdisk/scratch/cdunn/repo/nim-falcon/repos/nim-DALIGNER/src/daligner? That's the key. I think the equivalent needs to be added when building dependencies.

@pb-cdunn
Copy link
Contributor Author

pb-cdunn commented Apr 5, 2019

@pb-cdunn
Copy link
Contributor Author

pb-cdunn commented Apr 5, 2019

Best solution so far:

from os import DirSep
from strutils import rsplit
const thisdir = system.currentSourcePath.rsplit(DirSep, 1)[0]
{.passC: "-I" & thisdir.}

cdunn2001 pushed a commit to bio-nim/nim-DALIGNER that referenced this issue Apr 5, 2019
cdunn2001 pushed a commit to bio-nim/nim-falcon that referenced this issue Apr 5, 2019
We are switching to nimble-install, after this small fix:

* nim-lang/Nim#10971
* https://forum.nim-lang.org/t/4768
cdunn2001 pushed a commit to bio-nim/nim-falcon that referenced this issue Apr 6, 2019
cdunn2001 pushed a commit to bio-nim/nim-falcon that referenced this issue Apr 6, 2019
@genotrance
Copy link
Contributor

You found the solution - tell the C compiler where the include files are. Why should Nim do this automatically?

@pb-cdunn
Copy link
Contributor Author

Nim already does it automatically, but only for the current module. The behavior is different when I module is used from another Nim module.

The reason this should work for dependencies is the same as the reason it was already made to work for the current (top) module.

@cdunn2001
Copy link
Contributor

cdunn2001 commented Oct 10, 2020

This remains a problem. I still don't understand the logic. Module A uses module B, and module B has .c and .h files. Module A does not know that module B needs those extra files. But module B compiles fine itself.

You can see my current solution here:

You can test this easily. Clone nim-edlib and switch to cpp branch. Then cd apps; make. That works. Then clear the cache and the .exe, remove the -I line from edlib.nim, and try again.

~/.cache/nim/aligner_d/aligner.nim.cpp:10:10: fatal error: 'edlib.h' file not found
#include "edlib.h"
         ^~~~~~~~~

@timotheecour
Copy link
Member

related to nim-lang/RFCs#510 ; please check whether it's an exact dup or not

@pb-cdunn
Copy link
Contributor Author

Hmm. Not quite the same, but yes, related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants