How to Resolving the “/bin/sh 1 not found” Issue in Linux

If you’ve encountered the error message “/bin/sh: 1: /home/me/SDKsAndFrameworks/intelFPGA/18.1/hld/bin/aoc -march=emulator /home/me/CLionProjects/cltest/vector_add.cl -o /home/me/CLionProjects/cltest/cmake-build-debug-openclintelfpgasimulation/vector_add.aocx: not found” while working on setting up a toolchain to compile OpenCL applications for Intel FPGAs in Linux, you’re not alone. This error can be quite perplexing, especially when you know that the command works perfectly when executed directly in the terminal. In this blog post, we’ll explore the issue and guide you on how to resolve it.

Understanding the Problem

The error message you’ve encountered points to a problem with how the command is being interpreted by the system. Specifically, it’s treating the entire command line as a single executable, which leads to the “/bin/sh: 1: not found” error.

In your CMakeLists.txt file, you have a custom command defined like this:

add_custom_command (OUTPUT "${CLKernelBinary}"
                    COMMAND "${aocExecutable} -march=emulator ${CLKernelSourceFile} -o ${CLKernelBinary}"
                    DEPENDS "${CLKernelSourceFile}"
)

The issue lies in the double quotes surrounding the COMMAND argument. In CMake, double quotes make the quoted string a single argument for a function or a macro, and in this case, it’s causing the entire command to be treated as a single executable.

You Might Like This:

The Solution

To resolve this issue, you should remove the double quotes around the COMMAND argument in your CMakeLists.txt file. Here’s the corrected custom command:

add_custom_command (OUTPUT "${CLKernelBinary}"
                    COMMAND ${aocExecutable} -march=emulator ${CLKernelSourceFile} -o ${CLKernelBinary}
                    DEPENDS "${CLKernelSourceFile}"
)

By doing this, you’re ensuring that the command is correctly interpreted, and it should work as expected.

Additional Considerations

Assuming you’ve successfully resolved the above problem, you may have an additional question: How can you make sure that the custom command is not only invoked if the output file is not present in the build directory but also if the CL source file was edited?

To achieve this, you need to add the CL source file to the DEPENDS list of your custom command. Here’s the updated command:

add_custom_command (OUTPUT "${CLKernelBinary}"
                    COMMAND ${aocExecutable} -march=emulator ${CLKernelSourceFile} -o ${CLKernelBinary}
                    DEPENDS "${CLKernelSourceFile}"
)

With this modification, the custom command will be re-run whenever the CL source file is edited, ensuring that your OpenCL kernels are always up-to-date.

In conclusion, resolving the “/bin/sh: 1: not found” issue in Linux is as simple as ensuring that your custom command is correctly defined in your CMakeLists.txt file. By removing unnecessary double quotes and specifying proper dependencies, you can make your OpenCL development workflow smoother and error-free. Happy coding!

Bipul author of nerdy tutorial
Bipul

Hello my name is Bipul, I love write solution about programming languages.

Articles: 146

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *