go-lang-plugin-org / go-lang-idea-plugin

Google Go language IDE built using the IntelliJ Platform
https://plugins.jetbrains.com/plugin/5047
Other
4.57k stars 574 forks source link

Unresolved reference (CLion 2016.2) #2686

Open tepsl opened 8 years ago

tepsl commented 8 years ago

Your issue description goes here. Please be as detailed as possible

clionscreensnapz001

Nothing is wrong before upgrading from CLion 2016.1 to CLion 2016.2.

simple_example.go

package main

import (
    "fmt"
    "encoding/base64"
)

func main() {
    fmt.Println(base64.StdEncoding.EncodeToString([]byte("abcdefg")))
}

CMakeDetermineGoCompiler.cmake

if(NOT CMAKE_Go_COMPILER)
    # prefer the environment variable CC
    if(NOT $ENV{GO_COMPILER} STREQUAL "")
        get_filename_component(CMAKE_Go_COMPILER_INIT $ENV{GO_COMPILER} PROGRAM PROGRAM_ARGS CMAKE_Go_FLAGS_ENV_INIT)
        if(CMAKE_Go_FLAGS_ENV_INIT)
            set(CMAKE_Go_COMPILER_ARG1 "${CMAKE_Go_FLAGS_ENV_INIT}" CACHE STRING "First argument to Go compiler")
        endif()
        if(NOT EXISTS ${CMAKE_Go_COMPILER_INIT})
            message(SEND_ERROR "Could not find compiler set in environment variable GO_COMPILER:\n$ENV{GO_COMPILER}.")
        endif()
    endif()

    set(Go_BIN_PATH
            $ENV{GOPATH}
            $ENV{GOROOT}
            $ENV{GOROOT}/../bin
            $ENV{GO_COMPILER}
            /usr/bin
            /usr/local/bin
    )
    # if no compiler has been specified yet, then look for one
    if(CMAKE_Go_COMPILER_INIT)
        set(CMAKE_Go_COMPILER ${CMAKE_Go_COMPILER_INIT} CACHE PATH "Go Compiler")
    else()
        find_program(CMAKE_Go_COMPILER
                NAMES go
                PATHS ${Go_BIN_PATH}
        )
    endif()
endif()
mark_as_advanced(CMAKE_Go_COMPILER)

# configure variables set in this file for fast reload later on
configure_file(CMakeGoCompiler.cmake
        ${CMAKE_PLATFORM_INFO_DIR}/CMakeGoCompiler.cmake @ONLY)
set(CMAKE_Go_COMPILER_ENV_VAR "GO_COMPILER")

CMakeGoCompiler.cmake

set(CMAKE_Go_COMPILER "@CMAKE_Go_COMPILER@")
set(CMAKE_Go_COMPILER_LOADED 1)

set(CMAKE_Go_SOURCE_FILE_EXTENSIONS go)
set(CMAKE_Go_LINKER_PREFERENCE 40)
set(CMAKE_Go_OUTPUT_EXTENSION .o)
set(CMAKE_Go_OUTPUT_EXTENSION_REPLACE 1)
set(CMAKE_Go_COMPILER_ENV_VAR "GO_COMPILER")

CMakeGoInformation.cmake

if(CMAKE_USER_MAKE_RULES_OVERRIDE)
    # Save the full path of the file so try_compile can use it.
    include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
    set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
endif()

if(CMAKE_USER_MAKE_RULES_OVERRIDE_Go)
    # Save the full path of the file so try_compile can use it.
    include(${CMAKE_USER_MAKE_RULES_OVERRIDE_Go} RESULT_VARIABLE _override)
    set(CMAKE_USER_MAKE_RULES_OVERRIDE_Go "${_override}")
endif()

if(NOT CMAKE_Go_COMPILE_OBJECT)
    #set(CMAKE_Go_COMPILE_OBJECT "go tool compile -I $ENV{GOPATH}/pkg/$ENV{GOOS}_$ENV{GOARCH} -l -N -o <OBJECT> <SOURCE>")
    set(CMAKE_Go_COMPILE_OBJECT "go build -o <OBJECT> <SOURCE>")
endif()
if(NOT CMAKE_Go_LINK_EXECUTABLE)
    #set(CMAKE_Go_LINK_EXECUTABLE "go tool link -L $ENV{GOPATH}/pkg/$ENV{GOOS}_$ENV{GOARCH} -o <TARGET> <OBJECTS>  ")
    set(CMAKE_Go_LINK_EXECUTABLE "cp -a <OBJECTS> <TARGET>")
endif()

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/)

project(simple_example Go)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")

set(SOURCE_FILES simple_example.go)

add_executable(simple_example ${SOURCE_FILES})

CMakeTestGoCompiler.cmake

set(CMAKE_Go_COMPILER_WORKS 1 CACHE INTERNAL "")

Be sure to set appropriate environment variables (GOPATH, GOOS, GOROOT, GOARCH) at Preferences -> Build, Execution, Deployment -> CMake -> Pass system environment. If it doesn't work, please edit .idea/workspace.xml as below;

  <component name="CMakeSettings" AUTO_RELOAD="false" GENERATION_PASS_SYSTEM_ENVIRONMENT="true">
    <ADDITIONAL_GENERATION_ENVIRONMENT>
      <envs>
        <env name="GOPATH" value="/somewhere/Go" />
        <env name="GOOS" value="darwin" />
        <env name="GOROOT" value="/usr/local/opt/go/libexec" />
        <env name="GOARCH" value="amd64" />
      </envs>
    </ADDITIONAL_GENERATION_ENVIRONMENT>
  </component>
dlsniper commented 8 years ago

Hi, can you please confirm you have a Go SDK attached to the IDE? Have a look under File | Settings | Languages & Frameworks | Go | Go SDK. If it's there, can you please also post a screenshot of the Project view (CTRL+1 usually)? I've just tried this under CLion 2016.2 and I cannot replicate it.

Thanks.

tepsl commented 8 years ago

@dlsniper Yes, Go SDK has been set. clionscreensnapz001

I'm not sure this is not what you meant but this is the screenshot of my project view; clionscreensnapz002

The project above is what I made for this issue and my project of practical use, which went very well on CLion 2016.1.3, shows vastly lots of unresolved references on CLion 2016.2.

tepsl commented 8 years ago

This is the screen shot of the same project opened by CLion 2016.1.3; clionscreensnapz001 4 29 39

Plugin version: 0.11.1682

dlsniper commented 8 years ago

That's strange, I don't see any external libs attached, see how I have it there: snapshot105 But I also don't have any of the C files there. I'll let Sergey / Alexander to tackle this going forward.

tepsl commented 8 years ago

@dlsniper FYI, I have never seen any External Libraries attached at Go project by CLion, even if it works well.

zolotov commented 8 years ago

@tepsl cannot recreate, could you try to unset Go SDK and then set again (File | Settings | Languages & Frameworks | Go | Go SDK)

tepsl commented 8 years ago

@zolotov
Finally I've got it working.

First time I did was to unset Go SDK in Preferences and press Apply and close Preferences. Then I opened Preferences and set Go SDK and saw the version was 1.6.2 although I had upgraded golang to 1.6.3. Cached, maybe? Opening the go project was still showing references unsolved. So I let it unset and quitted CLion and started again. This time setting Go SDK showed 1.6.3. Now the go project shows all references solved.

The point is just to unset Go SDK didn't make any sense. To unset, apply, quit, and set seems to be required.

Anyway, thank you for the instruction.

P.S. External Libraries is still empty as before.

zolotov commented 8 years ago

@tepsl thank you for update. I'm happy it works.

I'll investigate this situation later

opalmer commented 8 years ago

@zolotov I was having the same problem has @tepsl and your suggestion fixed the problem, thanks.

Normally I'd avoid posting because this sounds like a 'me too' comment but I thought I should because I had the same problem outside of CLion:

Happy to provide additional context if needed.

trestletech commented 7 years ago

For the sake of future Googlers -- this issue can also occur if you "exclude" a directory from your project that contains sources that you need. Doesn't render a total failure but sporadically was producing these issues for me.

I haven't been able to repro with a minimal example, but marking my internal GOPATH dir as not excluded fixed similar issues for me.