How does CLion check external Compiler?
I want to use CLion fro development of MSP430 chips firmware. The msp430-elf-gcc compiler has to be used as well as and 2 or 3 include directories with general C-headers and MSP430-specific headers and linker command files (.LD)
My problem: CLion has accepted the path to a Compiler and include directories, but the Compiler Test fails.
1) Here is the single source file
#include <stdio.h>
#define __MSP430FR5959__
#include <msp430.h>
int main() {
P1DIR = 0;
printf("Hello, World!\n");
return 0;
}
2) Here is CMakeLists.txt:
cmake_minimum_required(VERSION 3.8)
project(test_msp)
set(SOURCE_FILES main.c)
add_executable(test_msp.elf ${SOURCE_FILES})
include_directories(/home/user/ti/msp430_gcc/include)
include_directories(/home/user/ti/msp430_gcc/msp430-elf/include)
3) I've added this to CMake settings
-D CMAKE_C_COMPILER=/home/user/ti/msp430_gcc/bin/msp430-elf-gcc
4) Compiler Test is invoked after the Reload CMake Project and it fails on the step of linking:
...
Linking C executable cmTC_4167c
/home/user/clion-2017.2.3/bin/cmake/bin/cmake -E cmake_link_script
CMakeFiles/cmTC_4167c.dir/link.txt --verbose=1
/home/user/ti/msp430_gcc/bin/msp430-elf-gcc
CMakeFiles/cmTC_4167c.dir/testCCompiler.c.o -o cmTC_4167c
/home/user/ti/msp430_gcc/bin/../lib/gcc/msp430-elf/6.2.1/../../../../msp430-elf/lib/libcrt.a(crt_movedata.o):
In function `.Loc.116.1':
(.crt_0300movedata+0x6): undefined reference to `__romdatastart'
So I see that the path to external Compiler is set OK, but the include_directories() are ignored. There are some include dirs in CMakeCache.txt
//C compiler system include directories
CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS:INTERNAL=
/home/user/ti/msp430_gcc/bin/../lib/gcc/msp430-elf/6.2.1/include;
/home/user/ti/msp430_gcc/bin/../lib/gcc/msp430-elf/6.2.1/include-fixed;
/home/user/ti/msp430_gcc/bin/../lib/gcc/msp430-elf/6.2.1/../../../../msp430-elf/include;
/home/user/ti/msp430_gcc/bin/../include
- but they seem to be auto-generated from Compile path: the 2-nd is not present in CMakeLists.txt and the last is added by me manually.
By the way, the stdio.h and msp430.h in the main.c file are marked as unresolved. It shows once more that something is wrong with include_directories()
请先登录再写评论。
Well, some new data on the topic. A simple pattern to play and replicate the problem.
1) Create a brand new C-project.
All default settings. A main.c is generated, Hello, World and so on. Test run shows everything OK!
And "Go to declaration" for "stdio.h" symbol leads to /usr/include - I think it's the right path for /ust/bin/cc Compiler
So far so good
The msp430.h and P1DIR are marked as not found and unresolved. Good.
3) Add to CMakeLists.txt a new path to stdio.h and a path to msp430.h. In my case it's here:
Now we can see, "Go to declaration" for "stdio.h" symbol leads to MSP430-GCC dir - it's OK!
msp430.h is being found too - and it it expected result.
But P1DIR has multiple choise - so we append this to CMakeLists.txt:
Now Go to definition for P1DIR leads to msp430fr5959.h - it is good!
The project cannot be compiled, the gcc Compiler dislikes the hardware definitions of micro controller - but it is not the point now.
We see that the new include directories ARE ACCEPTED by CLion IDE.
4) Drums... Add the new C Compiler. Add to CMake settings an option:
...and everything crashes!
The C compiler is not able to compile a simple test program
All External Libraries are gone!
This is a stop point, till a JetBrains helps.
I resolved a problem in my way - compiling with CCS the source files, edited with CLion. This is a very primitive workaround, of course.
Hi! The issue looks related rather to CMake than to CLion. Could you please try to build your simple "Hello" program with CMake and the msp430-elf-gcc compiler outside CLion (from the terminal/command line)? Is it working in this case?
Hi!
I can not. Too weak in CMake domain.
My tries:
1) Launch msp-gcc from command line
COMPILERPATH/bin/msp430-elf-gcc main.c -mmcu=msp430fr5959 -I"COMPILERPATH/msp430-elf/include" -I"INCLUDEPATH/include_gcc"
Result ok, file a.out is produced.
N.B. May be important: I had to place physically 2 files (command and symbols) into the source dir - though they are present in INCLUDE dir:
msp430fr5959.ld
msp430fr5959_symbols.ld
If I place these files in source (and CMakeFiles) dir - the CLion behavior doesn't change.
2) I try to generate CMake files to launch it from command line but to no avail.
After setting CMAKE_TOOLCHAIN_FILLE I get error:
Well, thanks to the help of CLion command I've solved the problem of building with msp430-gcc under the CLion. Still, I cannot state that I have an answer to my question: how does the check of new Compiler proceeds. No worry, though.
Don't know how to mark the topic as solved.