-
Notifications
You must be signed in to change notification settings - Fork 10
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
Multiple files and "undefined reference" #2
Comments
@ramboza, this is one weirdness of the Arduino CMake but you need to add linked directories which hold additional "library" files locally that will be scanned to find included .h/.cpp combinations where the names match. In your case the files are in the root of your project so add this line and it should fix it:
BTW, I missed a few bugs in the last release which are now fixed. Until now I did not know if anyone was using the plugin. Thank you for being the first one. |
Result the same :( |
@ramboza, I'll try it now. |
My setup - macOS Mojave, Arduino IDE 1.8.7, tried CMake version 3.13.1 and 3.12.3 (bundled with CLion) Thanks !!! |
@ramboza, forgot that the included lib files should be in a sub-directory with the same name as the files. In your case create You can include the
|
👍 awesome!! It works now!! Thank you Vladimir! |
Exists a more elegant solution for compile multiple cpp sources? |
I just installed Clion 2019.2 and no matter what I try, I am not able to get this simple example to work. The outcome is always (the name of my .ino file is CLion_Demo): Please help! |
@ramboza, the easiest way to make multi-file projects work is to rename the .ino to .cpp and add all your .cpp files to project sources in CMakeLists.txt and .h files to project headers. See: #17 Otherwise, you need to add your xxx files to a subdirectory named xxx located in your source directory if you use to add current source to linked directories with CMakeLists.txt config:
This is the weirdness of Arduino CMake and this plugin uses that project to make it work in CLion. |
@vsch , unfortunately, this doesn't work. While everything compiles properly, there is the linker error: undefined reference. I am sure there is something really simple that I am overlooking. Could you possibly try this out and let me know what's wrong? clion_demo.cpp void setup() { void loop() {} xxx.h: class XXX { #endif //CLION_DEMO_XXX_H My CMakeLists.txt: set(${PROJECT_NAME}_BOARD mega) Define additional source and header files or default arduino sketch filesset(${PROJECT_NAME}_SRCS clion_demo.cpp xxx.cpp) Additional static libraries to include in the target.set(${PROJECT_NAME}_LIBS)Main sketch fileset(${PROJECT_NAME}_SKETCH clion_demo.cpp) Add project directories into the build#add_subdirectory() Additional settings to add non-standard or your own Arduino libraries.For this example (libs will contain additional arduino libraries)An Arduino library my_lib will contain files in libs/my_lib/: my_lib.h, my_lib.cpp + any other cpp fileslink_directories(${CMAKE_CURRENT_SOURCE_DIR}/libraries) For nested library sources replace ${LIB_NAME} with library name for each libraryset(_RECURSE true)Additional settings for programmer. From programmers.txtset(${PROJECT_NAME}_PROGRAMMER avrispmkii) set(mega.upload.speed 9600)Verbose build processset(${PROJECT_NAME}_AFLAGS -v)generate_arduino_firmware(${CMAKE_PROJECT_NAME}) |
@mweber-ovt, try commenting out the SKETCH defining line in CMakeLists.txt. If it is defined it will still try to process the project as a sketch and ignore the extra cop files. I’m guessing but the sketch line definitely has to be commented out for multi file project to work. |
For future reference (edit these two lines in your own project): francoiscampbell/arduino-cmake#10 After this de _SKETCH, _SRCS and _HDRS all work. |
Hi !
Nice plugin, thanks!!!
I have some problem to compile more than one source (ino) file.
example:
CLion 2018.3, plugin v1.4.0
I have simple project with one additional cpp file..
demo.ino
xxx.cpp
xxx.h
and result is
I tried to use different ways from CMakeLists.txt, result the same ..
so, this is some problem of compiling xxx.cpp and linking together with demo.ino
any ideas how to solve it ?
Thanks a lot!
Jev.
The text was updated successfully, but these errors were encountered: