zezer3 / cmaked2

Automatically exported from code.google.com/p/cmaked2
0 stars 0 forks source link

Test fail while looking for generated files #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi guys, thanks for working on this.

I am using the tip under linux (76f2e292de4d tip), ubuntu 10.10 and cmake 2.8.2.

I followed the steps on the tutorial wiki, and the installation went smooth. 
However both my program and the included tests fail to build. CMake runs 
correctly, despite it says dmd is unknown:

jordi@han:~/d2/cmaked2/tests/build$ cmake ..
-- The C compiler identification is GNU
-- The D compiler identification is unknown
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
**** Debug Info: Enter CMakeDInformation.cmake
**** Debug Info: CMAKE_SYSTEM_NAME = Linux
**** Debug Info: CMAKE_D_COMPILER_ID = 
**** Debug Info: CMAKE_BASE_NAME = dmd
**** Debug Info: Enter Linux-dmd.cmake
**** Debug Info: Exit Linux-dmd.cmake
**** Debug Info: Exit CMakeDInformation.cmake
-- Check for working D compiler: /home/jordi/d2/dmd2/linux/bin/dmd
**** Debug Info: Enter CMakeDInformation.cmake
**** Debug Info: CMAKE_SYSTEM_NAME = Linux
**** Debug Info: CMAKE_D_COMPILER_ID = 
**** Debug Info: CMAKE_BASE_NAME = dmd
**** Debug Info: Enter Linux-dmd.cmake
**** Debug Info: Exit Linux-dmd.cmake
**** Debug Info: Exit CMakeDInformation.cmake
-- Check for working D compiler: /home/jordi/d2/dmd2/linux/bin/dmd -- works
-- Detecting D compiler ABI info
**** Debug Info: Enter CMakeDInformation.cmake
**** Debug Info: CMAKE_SYSTEM_NAME = Linux
**** Debug Info: CMAKE_D_COMPILER_ID = 
**** Debug Info: CMAKE_BASE_NAME = dmd
**** Debug Info: Enter Linux-dmd.cmake
**** Debug Info: Exit Linux-dmd.cmake
**** Debug Info: Exit CMakeDInformation.cmake
-- Detecting D compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jordi/d2/cmaked2/tests/build

when calling make, as seen below, some files are built but then they cannot be 
located:

jordi@han:~/d2/cmaked2/tests/build$ make
Scanning dependencies of target lib_1
[ 10%] Building D object lib_1/CMakeFiles/lib_1.dir/lib_1.o
Linking D static library liblib_1.a
Error: Error reading file 'CMakeFiles/lib_1.dir/lib_1.o'

make[2]: *** [lib_1/liblib_1.a] Error 1
make[1]: *** [lib_1/CMakeFiles/lib_1.dir/all] Error 2
make: *** [all] Error 2

The file actually exists in the relative path from where i am calling, and it 
has reading permission for everybody.
Finally:

jordi@han:~/d2/cmaked2/tests/build$ make test
Running tests...
Test project /home/jordi/d2/cmaked2/tests/build
    Start 1: app_1
Could not find executable app_1
Looked in the following places:
app_1
app_1
Release/app_1
Release/app_1
Debug/app_1
Debug/app_1
MinSizeRel/app_1
MinSizeRel/app_1
RelWithDebInfo/app_1
RelWithDebInfo/app_1
Deployment/app_1
Deployment/app_1
Development/app_1
Development/app_1
Unable to find executable: app_1
1/7 Test #1: app_1 ............................***Not Run   0.00 sec
    Start 2: app_2
Could not find executable app_2
Looked in the following places:
app_2
app_2
Release/app_2
Release/app_2
Debug/app_2
Debug/app_2
MinSizeRel/app_2
MinSizeRel/app_2
RelWithDebInfo/app_2
RelWithDebInfo/app_2
Deployment/app_2
Deployment/app_2
Development/app_2
Development/app_2
Unable to find executable: app_2
2/7 Test #2: app_2 ............................***Not Run   0.00 sec
    Start 3: app_3
Could not find executable app_3
Looked in the following places:
app_3
app_3
Release/app_3
Release/app_3
Debug/app_3
Debug/app_3
MinSizeRel/app_3
MinSizeRel/app_3
RelWithDebInfo/app_3
RelWithDebInfo/app_3
Deployment/app_3
Deployment/app_3
Development/app_3
Development/app_3
Unable to find executable: app_3
3/7 Test #3: app_3 ............................***Not Run   0.00 sec
    Start 4: app_5
Could not find executable app_5
Looked in the following places:
app_5
app_5
Release/app_5
Release/app_5
Debug/app_5
Debug/app_5
MinSizeRel/app_5
MinSizeRel/app_5
RelWithDebInfo/app_5
RelWithDebInfo/app_5
Deployment/app_5
Deployment/app_5
Development/app_5
Development/app_5
Unable to find executable: app_5
4/7 Test #4: app_5 ............................***Not Run   0.00 sec
    Start 5: app_4
Could not find executable app_4
Looked in the following places:
app_4
app_4
Release/app_4
Release/app_4
Debug/app_4
Debug/app_4
MinSizeRel/app_4
MinSizeRel/app_4
RelWithDebInfo/app_4
RelWithDebInfo/app_4
Deployment/app_4
Deployment/app_4
Development/app_4
Development/app_4
Unable to find executable: app_4
5/7 Test #5: app_4 ............................***Not Run   0.00 sec
    Start 6: app_6
Could not find executable app_6
Looked in the following places:
app_6
app_6
Release/app_6
Release/app_6
Debug/app_6
Debug/app_6
MinSizeRel/app_6
MinSizeRel/app_6
RelWithDebInfo/app_6
RelWithDebInfo/app_6
Deployment/app_6
Deployment/app_6
Development/app_6
Development/app_6
Unable to find executable: app_6
6/7 Test #6: app_6 ............................***Not Run   0.00 sec
    Start 7: app_7
Could not find executable app_7
Looked in the following places:
app_7
app_7
Release/app_7
Release/app_7
Debug/app_7
Debug/app_7
MinSizeRel/app_7
MinSizeRel/app_7
RelWithDebInfo/app_7
RelWithDebInfo/app_7
Deployment/app_7
Deployment/app_7
Development/app_7
Development/app_7
Unable to find executable: app_7
7/7 Test #7: app_7 ............................***Not Run   0.00 sec

0% tests passed, 7 tests failed out of 7

Total Test time (real) =   0.01 sec

The following tests FAILED:
      1 - app_1 (Not Run)
      2 - app_2 (Not Run)
      3 - app_3 (Not Run)
      4 - app_5 (Not Run)
      5 - app_4 (Not Run)
      6 - app_6 (Not Run)
      7 - app_7 (Not Run)
Errors while running CTest
make: *** [test] Error 8

Original issue reported on code.google.com by camin...@gmail.com on 13 Sep 2010 at 2:18

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Which version of dmd are you using? I can reproduce your problem with version 
2.039. But with version 2.049 it works. Can you try version 2.049?

Original comment by jens.k.mueller@gmail.com on 20 Sep 2010 at 2:40

GoogleCodeExporter commented 9 years ago
I was using 2.048. Now I moved to 2.049 and the cmaked2 tests work fine.

My own project also compiles fine, however it fails to link with the message:
Linking D executable taula
Error: unrecognized switch '-lpthread'

I have no reference to pthreads in my makefiles or code, and i have seen that 
cmaked2 only has one but it is commented out. Then i have seen that the dmd 
source code contains this:
./dmd2.0.49/src/dmd/link.c:    argv.push((void *)"-lpthread");

Which makes me think that the option is being added my dmd itself. I have seen 
though, that the test app7 uses threads and it seems to work fine.

I will try to investigate a little bit more.

Original comment by camin...@gmail.com on 20 Sep 2010 at 3:57

GoogleCodeExporter commented 9 years ago
Enabling the cmake verbose mode i get the failing command:

Linking D executable taula
cd /home/jordi/d2/crosa/build/debug/taula && /usr/bin/cmake -E 
cmake_link_script CMakeFiles/taula.dir/link.txt --verbose=1
/home/jordi/d2/dmd2/linux/bin/dmd  -g -debug -L--export-dynamic   
CMakeFiles/taula.dir/application.o -oftaula  ../crosa/libcrosa.a 
../extern/derelict/libderelict.a -L-ldl /usr/lib/libfreetype.so 
/usr/lib/libSDLmain.a /usr/lib/libSDL.so -lpthread /usr/lib/libGLU.so 
/usr/lib/libGL.so /usr/lib/libSM.so /usr/lib/libICE.so /usr/lib/libX11.so 
/usr/lib/libXext.so  
Error: unrecognized switch '-lpthread'

It seems all the last part of the command might come from the cmake commands to 
locate the SDL, FreeType, GL and DevIL libraries. I have modified the app7 
CMakeLists.txt of the tests like this:

# A more complex library test.
include( FindOpenGL )

ADD_EXECUTABLE( app_7 app_7.d )
ADD_TEST( app_7 app_7 )
target_link_libraries( app_7

    ${OPENGL_LIBRARIES}

)

And it generates a simialr problem (not with pthreads, but with extra linking 
parameters).

I am currently used a hacked and slashed version of the cmaked in dsource that 
i patched long time ago. It works for my case even with this external 
libraries. Unfortunately i modified it in a careless way and it is not useful 
for other projects. I ay try to look at how this is handled in that version.

Original comment by camin...@gmail.com on 20 Sep 2010 at 4:22

GoogleCodeExporter commented 9 years ago
More info: my patched version actually uses gcc for linking. Generating this 
command:

Linking D executable taula
cd /home/jordi/d2/crosa/build/debug/taula && /usr/bin/cmake -E 
cmake_link_script CMakeFiles/taula.dir/link.txt --verbose=1
gcc    CMakeFiles/taula.dir/application.d.o -o taula  ../crosa/libcrosa.a 
../extern/derelict/libderelict.a -ldl /usr/lib/libfreetype.so 
/usr/lib/libSDLmain.a /usr/lib/libSDL.so -lpthread /usr/lib/libGLU.so 
/usr/lib/libGL.so /usr/lib/libSM.so /usr/lib/libICE.so /usr/lib/libX11.so 
/usr/lib/libXext.so  -lpthread -lm -L/home/jordi/d2/dmd2/linux/lib -lphobos2 
-ldruntime

Original comment by camin...@gmail.com on 20 Sep 2010 at 4:26

GoogleCodeExporter commented 9 years ago
I think the problem is that dmd uses a weird syntax for command line parameters 
passed through to the linker.  The syntax should be -L-lpthread.  Somehow the 
wrong syntax -lpthread is sneaking in there.

Eventually I would like to leave the existing regression tests alone, but add a 
new test to try and catch this pthread issue.

Original comment by kingshiz...@gmail.com on 21 Sep 2010 at 3:18

GoogleCodeExporter commented 9 years ago
Even though this issue now moved into another direction, I tried using 
dmd.2.048 to reproduce the original issue ("Error: Error reading file 
'CMakeFiles/lib_1.dir/lib_1.o'") but I couldn't reproduce. I tried also 
dmd.2.047 which works as well. But with dmd.2.039 I can reproduce it. Are you 
sure about your dmd version?

Original comment by jens.k.mueller@gmail.com on 21 Sep 2010 at 8:06

GoogleCodeExporter commented 9 years ago
A possible test could be:

find_package(Threads)

# A more complex library test.
ADD_EXECUTABLE( app_7 app_7.d )
target_link_libraries(app_7
        -L${CMAKE_THREAD_LIBS_INIT}
)

ADD_TEST( app_7 app_7 )

And a quick workaround is changing "-L${CMAKE_THREAD_LIBS_INIT}" to 
"-L${CMAKE_THREAD_LIBS_INIT}".
Anyway we should try to make cmake add the "-L" for us.
The next problem is that shared libraries are not supported by dmd yet. In the 
meantime one could try to use gcc as linker as you did. How did you do this?

Original comment by jens.k.mueller@gmail.com on 21 Sep 2010 at 8:34

GoogleCodeExporter commented 9 years ago
I have it nastily hardcoded in the CMakeDInformation.cmake file like this:

IF(NOT CMAKE_D_LINK_EXECUTABLE)

  IF(CMAKE_COMPILER_IS_GDC)

    SET(CMAKE_D_LINK_EXECUTABLE

      "<CMAKE_D_COMPILER> <FLAGS> <CMAKE_D_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> ${CMAKE_OUTPUT_D_FLAG}<TARGET> <LINK_LIBRARIES> ${DSTDLIB_FLAGS} ${DSTDLIB_TYPE}")

  ELSE(CMAKE_COMPILER_IS_GDC)

    IF(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

      SET(CMAKE_D_LINK_EXECUTABLE

    "gcc ${DLINK_FLAGS} <CMAKE_D_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -lpthread -lm ${DSTDLIB_FLAGS}")

    ELSE(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

      SET(CMAKE_D_LINK_EXECUTABLE

    "<CMAKE_D_COMPILER> <FLAGS> <CMAKE_D_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> ${CMAKE_OUTPUT_D_FLAG}<TARGET> <LINK_LIBRARIES>")

    ENDIF(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

  ENDIF(CMAKE_COMPILER_IS_GDC)

ENDIF(NOT CMAKE_D_LINK_EXECUTABLE)

but this is not an option for the general case. 
Your solution of prepending -L in the comment 8, wouldn't work in the case of 
more than one parameter in the CMAKE_THREAD_LIBS_INIT variable, though.

Original comment by camin...@gmail.com on 22 Sep 2010 at 12:27

GoogleCodeExporter commented 9 years ago
I've been searching a bit for the -lpthread problem. The problem is that the 
'-lpthread' is more or less hard coded in cmake's FindThreads.cmake. I don't 
know why they do it like this.
The OpenGL example fails because it tries linking a shared object but dmd does 
not support linking shared libraries. Unfortunately I don't know how to tell 
cmake to use the a static library version of OpenGL. With FindBoost you can set 
Boost_USE_STATIC_LIBS. 

Original comment by jens.k.mueller@gmail.com on 27 Sep 2010 at 9:53

GoogleCodeExporter commented 9 years ago
Hi again,

  It seems to be the normal way for all CMake commands of the type FindXXXX to return a set of parameters for the C/C++ compiler and linker that shouldn't be "manipulated" and just passed directly. In the case of OpenGL for example, it doesn't usually make sense to use static libraries, as the GL library itself is part of the graphic driver which change from computer to computer.

  I presume this is the reason why the previous developers of cmaked were using gcc for linking in Linux.

  What are the benefits of using dmd? In linux at least, dmd will still use gcc's linker internally, i think. But this might be a question for the dmd developers...

j.

Original comment by camin...@gmail.com on 28 Sep 2010 at 1:45

GoogleCodeExporter commented 9 years ago
Good question about linking with dmd vs. gcc.  If there is a clear winner, it's 
easy to change the weighted preference.

Original comment by kingshiz...@gmail.com on 28 Sep 2010 at 4:08

GoogleCodeExporter commented 9 years ago
I just came around a way to make the workaround less nasty. Maybe even good.

add_executable(foo src/bar.d)
target_link_libraries(foo /path/to/lib/libphobos2.a)
set_target_properties(foo PROPERTIES LINKER_LANGUAGE C)

The key observation is that you can define which language to use for linking.
What do you think?
But one should provide a way of finding the phobos2 library. So it becomes:
find_package(Phobos2)
target_link_libraries(foo ${PHOBOS2_LIBRARIES})

Original comment by jens.k.mueller@gmail.com on 3 Nov 2010 at 8:34

GoogleCodeExporter commented 9 years ago
I added a FindPhobos.cmake to the repository.

find_package(Phobos)
target_link_libraries(foo ${PHOBOS_LIBRARY})

should work.
Beware that I check for the import/include path _and_ the library path.
You have to set proper paths for this. E.g.
cmake -DCMAKE_PREFIX_PATH="/path/to/lib;/path/to/src/phobos/"

Original comment by jens.k.mueller@gmail.com on 3 Nov 2010 at 9:20