7
votes

I am using CLion 2016.1.1 on Ubuntu (16.04)

When I compile my project, the CMake output shows:

/opt/clion/bin/cmake/bin/cmake --build 
/home/glapworth/.CLion2016.1/system/cmake/generated/project_name-f43e0982/f43e0982/Debug --target all -- -j 8
[ 33%] Linking C executable 
/home/glapworth/src/project/project_name/bin/project_name

However, when I execute:

/opt/clion/bin/cmake/bin/cmake --build /home/glapworth/.CLion2016.1/system/cmake/generated/project_name-f43e0982/f43e0982/Debug --target all -- -j 8

I can see the compiler error:

...
CMakeFiles/project.dir/src/main.c.o: In function `main':
/home/glapworth/src/project/project_name/src/main.c:22: undefined reference to `curl_global_init'
...

How can I get CLion to show the compiler errors or warnings?

3
If cilon not show compile error, then this is a bug in clionfghj
Build with VERBOSE=yes and find the difference in the compiler invocation.arved
When I build with set(CMAKE_VERBOSE_MAKEFILE ON) I still don't see the error. The compiler invocation is /usr/bin/gcc -Werror -Wall -g -o CMakeFiles/project.dir/src/main.c.o -c /home/glapworth/src/project/project/src/main.c which is correct. When running the same command from a terminal, I can clearly see the compiler errors. It looks like STDERR is being redirected away from the Messages tab in CLion :(glapworth

3 Answers

4
votes

here's bug-report https://youtrack.jetbrains.com/issue/CPP-6559

No, CLion shows all compile errors. You can't compile a project if you have errors.

But, CLion shows notices only once during build time, until you make a clean build, you will not see them again. Because you have already compiled object files and CLion (CMake) will not rebuild them if you haven't changed source files.

CMake assumes you know what your'e doing and does not rebuild all your codebase from scratch, so you don't see notices after the first compile run.

1
votes

It seems that CLion only shows the error on the first compile. If you've accidentally compiled a second time, you'll not be able to see the error output. I've since moved back to vim.

However, if you want to stick with CLion, and you are having the same problem, you can build the Makefile manually; In the source directory that contains the CMakeLists.txt

cmake . make

This will allow you to compile on demand from a terminal.

I also tend to set the build directoy to ./bin by editing the CMakeLists.txt to include the following line

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

0
votes

You have to check your CMakeLists.txt. What does it look like? You can also try and clean your code, tool -> cmake -> refresh (both options) and have a regular Makefile that your build with so if Clion doesn't inform you about what's wrong then you can build with a regular Makefile . My CMakeLists.txt looks like this

cmake_minimum_required(VERSION 2.8.12)
project(project001)
set(CMAKE_VERBOSE_MAKEFILE on)
file(GLOB SOURCES "./*.c")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -pedantic")
add_executable(project001 ${SOURCES})
target_link_libraries(project001 readline)

My Makefile for the same project is

CC = gcc
GIT_VERSION := $(project001 git describe --abbrev=4 --dirty --always --tags)
CFLAGS := $(CFLAGS) -pedantic -std=c99 -Wall -O3 -ledit -g -DVERSION=\"$(GIT_VERSION)\"

project001: main.o
    $(CC) -o project001 main.o errors.c util.c pipeline.c -ledit

main.o: main.c errors.c util.c

.PHONY: clean
clean:
    rm -f *.o

If Clion can't compile, then I fix the errors at the prompt and I use Clion to analyze my code so that it compiles without errors, then I can clean the project in Clion and run it from within Clion again.