0

I am currently working on a large project which is using clang to build files. Now the issue is that when creating executable file for windows, clang is able to create that but when doing the same for linux, I am getting the following error:-

clang++ -pthread -rdynamic -fopenmp -Wl,-rpath-link= -Wl,--no-undefined -Wl,--strip-discarded -Wl,--gc-sections -m64 -o ./File @File.rsp
/usr/bin/ld: obj/File/File.o: in function `main':
/mnt/d/File/File/out/lin/../../File/File.cpp:186: undefined reference to `Function1()'
/usr/bin/ld: /mnt/d/File/File/out/lin/../../File/File.cpp:197: undefined reference to `Function2()'
/usr/bin/ld: /mnt/d/File/File/out/lin/../../File/File.cpp:218: undefined reference to `Function3()'
/usr/bin/ld: /mnt/d/File/File/out/lin/../../File/File.cpp:226: undefined reference to `Function4()'
/usr/bin/ld: /mnt/d/File/File/out/lin/../../File/File.cpp:233: undefined reference to `Function4()'
/usr/bin/ld: /mnt/d/File/File/out/lin/../../File/File.cpp:274: undefined reference to `Function4()'
/usr/bin/ld: /mnt/d/File/File/out/lin/../../File/File.cpp:288: undefined reference to `Function4()'
/usr/bin/ld: /mnt/d/File/File/out/lin/../../File/File.cpp:297: undefined reference to `Function5()'
/usr/bin/ld: /mnt/d/File/File/out/lin/../../File/File.cpp:309: undefined reference to `Function6()'
/usr/bin/ld: /mnt/d/File/File/out/lin/../../File/File.cpp:316: undefined reference to `Function7()'
/usr/bin/ld: /mnt/d/File/File/out/lin/../../File/File.cpp:325: undefined reference to `Function8()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Now, I think that there might not be issue in code because if there was then it shouldn't be running in windows. How can I overcome this issue in linux? Any Help Would be highly appreciated.

  • What is in your response file `@File.rsp`? – David C. Rankin Jul 02 '21 at 07:27
  • @DavidC.Rankin This is inside the rsp file-obj/File/File.o Core.so – Rohit Nagpal Jul 02 '21 at 07:31
  • @DavidC.Rankin Core.so is my shared library – Rohit Nagpal Jul 02 '21 at 07:32
  • Since the response file is envisioned for use with a number of arguments so large it would exceed the OS command-line limit (thousands of files), try eliminating the response file and using the explicit command line arguments. (it shouldn't matter, but that is one thought) clang cannot find the source file (or object file) that contains the`Function1(), ...` So where are those functions "defined"? That usually indicates you have a necessary source or object file that is missing from the compiler command line. – David C. Rankin Jul 02 '21 at 07:36
  • @DavidC.Rankin How to make clang find source Files?. I know where the functions are defined. – Rohit Nagpal Jul 02 '21 at 07:39
  • I would just add the full path to the file you need to include for the `Function1(), ...` to your clang command line, e.g. `clang++ -pthread -rdynamic ... /path/to/where/file/with/Functions.c` (or `.o` if it is an object file) If it is a library, then use `-L/path/to/where/lib/is`. – David C. Rankin Jul 02 '21 at 07:45
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – 273K Jul 02 '21 at 07:47
  • @S.M. I don't think path issue is discussed there. – Rohit Nagpal Jul 02 '21 at 08:11
  • @DavidC.Rankin I have used LD_LIBRARY_PATH to set path to library, but still getting the same error. – Rohit Nagpal Jul 02 '21 at 08:11
  • Since you are working between WSL and windows through `/mnt` is there any chance you have a path syntax issue in your library path. Also check, you may need simply `LIBRARY_PATH` instead of `LD_LIBRARY_PATH`. – David C. Rankin Jul 02 '21 at 08:59
  • @DavidC.Rankin I have set the `LIBRARY_PATH` but still getting the same error. – Rohit Nagpal Jul 02 '21 at 09:13
  • @DavidC.Rankin `LIBRARY_PATH=mnt/path/to/lib`. This is how i set it up and then exported it. – Rohit Nagpal Jul 02 '21 at 09:22
  • Unless you have `mnt` as a local subdirectory, then I would expect `LIBRARY_PATH=/mnt/path/to/lib` as an absolute pathname – David C. Rankin Jul 02 '21 at 09:25
  • @DavidC.Rankin Also, Removing `mnt` from path doesn't bring results. – Rohit Nagpal Jul 02 '21 at 09:31
  • Why remove it? If the file is on the windows side, you have to go through `/mnt` but just make sure there is a `'/'` before `'mnt'`, e.g. `/mnt/rest/of/path` (not `mnt/rest/of/path` – David C. Rankin Jul 02 '21 at 09:35
  • @DavidC.Rankin I tried adding `/` but still the same issue. – Rohit Nagpal Jul 02 '21 at 09:39
  • I always go back to basics when this occurs. Is the file containing the `Function1(), ...` a library you are attempting to use? If so, was is compiled in a way that is compatible with your compiler and the libraries you have in WSL? Generally I would expect a SONAME error or something similar pointing out the version issues. If you compiled the library, was is compiled with `-fPIC` ensuring position independent code. Does your compile string contain `-lname` where your library is `libname.so`? Double-check all. – David C. Rankin Jul 02 '21 at 22:10
  • @DavidC.Rankin This command is working `clang++ -pthread -rdynamic ... /path/to/where/file/with/Functions.c` but I have a huge number of cpp files and including them will seriously take much time. What to do now? – Rohit Nagpal Jul 03 '21 at 19:50
  • A generic Makefile and using `make` is the way to go. See [Getting make to create object files in a specific directory](https://stackoverflow.com/q/14639794/3422102) as well as searching "generic makefile" in the StackOverflow search box. – David C. Rankin Jul 04 '21 at 04:29
  • @DavidC.Rankin But I am using GN to create build files. Should I use MakeFile for these changes? – Rohit Nagpal Jul 04 '21 at 11:39
  • You can use whichever will work for you. I'm not familiar with GN, but I'm sure you can search here and find a number of relevant questions and answers. – David C. Rankin Jul 05 '21 at 01:23

0 Answers0