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

Bug: Duplicate symbols if there multiple source files have the same name #683

Closed
jerry73204 opened this issue May 31, 2022 · 3 comments · Fixed by #684
Closed

Bug: Duplicate symbols if there multiple source files have the same name #683

jerry73204 opened this issue May 31, 2022 · 3 comments · Fixed by #684

Comments

@jerry73204
Copy link

The compile() complains about duplicate symbols when there are multiple input files with the same name but in different directories. The cc names the object file by its source file and places them under OUT_DIR. It causes one object file to replace the other file, and pack the last object file twice in the .a static library.

This is an example of the occurrence. The target/debug/build/xxx/output log shows that two empty__functions.c files from different dirs are compiled into empty_functions.o in the same directory.

running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/xxx/include" "-Wall" "-Wextra" "-o" "/my-crate/target/debug/build/rclrust-msg-ac6046ca5e70df07/out/empty__functions.o" "-c" "/xxx/include/std_msgs/msg/detail/empty__functions.c"
...
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/xxx/include" "-Wall" "-Wextra" "-o" "/my-crate/target/debug/build/rclrust-msg-ac6046ca5e70df07/out/empty__functions.o" "-c" "/xxx/include/std_srvs/srv/detail/empty__functions.c"
...
@dot-asm
Copy link
Contributor

dot-asm commented Jun 1, 2022

Yeah... This happens if you specify source files by absolute path. Do you? If you specify them by relative path, then sub-directories will be reflected in -o arguments. One can argue if it's actually a bug or not. After all, the natural expectation would be that the common bias would be removed from the source files, but it's tricky to figure one out... Of course one can just as well say that it should graft absolute paths as if they were relative, but then you formally run higher risk of hitting some limit... Meanwhile it appears to be possible to env::set_current_dir(<your-absolute-path>) and then specify source files by relative path. "Appears to be possible" means that I did some quick testing and it worked, but didn't try to figure out if there are some pitfalls... set_currect_dir affects only the build script itself, and all other paths are absolute...

dot-asm added a commit to dot-asm/cc-rs that referenced this issue Jun 1, 2022
If a source file was specified by absolute path, then the corresponding
object file was placed into OUT_DIR. This posed a problem if multiple
files with the same base name were specified by absolute paths.

Fixes rust-lang#683.
@dot-asm
Copy link
Contributor

dot-asm commented Jun 1, 2022

One can argue if it's actually a bug or not.

But just in case I've opened #684. You can test it by referring to cc as { git = "https://github.com/dot-asm/cc-rs", branch = "compiling-absolute-paths" } in your Cargo.toml.

@jerry73204
Copy link
Author

I compiled *.c files in ROS directory /opt/ros/foxy directly. I tried to avoid writing C source code in my repository. That's why I passed absolute paths the cc. I prefer not to replace files with the same names or provide an option in cc to control the behavior.

dot-asm added a commit to dot-asm/cc-rs that referenced this issue Jul 11, 2022
If a source file was specified by absolute path, then the corresponding
object file was placed into OUT_DIR. This posed a problem if multiple
files with the same base name were specified by absolute paths.

Fixes rust-lang#683.
dot-asm added a commit to dot-asm/cc-rs that referenced this issue Nov 3, 2022
If a source file was specified by absolute path, then the corresponding
object file was placed into OUT_DIR. This posed a problem if multiple
files with the same base name were specified by absolute paths.

Fixes rust-lang#683.
dot-asm added a commit to dot-asm/cc-rs that referenced this issue Nov 24, 2022
If a source file was specified by absolute path, then the corresponding
object file was placed into OUT_DIR. This posed a problem if multiple
files with the same base name were specified by absolute paths.

Fixes rust-lang#683.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants