Skip to content
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

Does this library actually work? #3

Closed
KamijoToma opened this issue Feb 10, 2022 · 5 comments
Closed

Does this library actually work? #3

KamijoToma opened this issue Feb 10, 2022 · 5 comments

Comments

@KamijoToma
Copy link

KamijoToma commented Feb 10, 2022

When I tried to compile this library with command cmake .., it reported a CMP0002 error:
CMake Error at CMakeLists.txt:50 (add_library): add_library cannot create target "tray" because another target with the same name already exists. The existing target is an interface library created in source directory "[Project Root Dir]". See documentation for policy CMP0002 for more details.

However, after I renamed the tray library to another name, a huge amount of errors came when I run ninja,
showing that there maybe some wrong in the code.
These errors contain:

  • Undefined type errors
    This is something like tray_windows.c:42:15: error: invalid use of undefined type 'struct tray_menu'',
    This kind of errors is solved after I added #include "tray.h" on the top of tray_windows.c(This problems may also exist in tray_linux.c and tray_darwin.m)
  • static method errors
    Something like example.c:(.text+0x11d): undefined reference to tray_exit'It comes out that methods defined intray_windows.care static methods, so thatexample.c` cannot call them.

According to those I explained above, I don't understand why those errors happen in this library.
Thank you for answering my question.
Apologize for my poor English.

@dmikushin
Copy link
Owner

Hello, let me first provide build logs for different platforms, so that we can justify yours and other's errors.

@dmikushin
Copy link
Owner

MacOS (builds successfully):

% git clone [email protected]:dmikushin/tray.git
Cloning into 'tray'...
remote: Enumerating objects: 242, done.
remote: Counting objects: 100% (63/63), done.
remote: Compressing objects: 100% (33/33), done.
remote: Total 242 (delta 32), reused 58 (delta 30), pack-reused 179
Receiving objects: 100% (242/242), 601.20 KiB | 1.82 MiB/s, done.
Resolving deltas: 100% (134/134), done.
% cd tray
% mkdir build
% cd build 
% cmake -G Ninja ..
-- The C compiler identification is AppleClang 11.0.0.11000033
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/marcusmae/forge/tray/build
% ninja
[1/4] Building C object CMakeFiles/tray_example.dir/example.c.o
../example.c:47:3: warning: implicit declaration of function 'tray_exit' is invalid in C99 [-Wimplicit-function-declaration]
  tray_exit();
  ^
../example.c:96:7: warning: implicit declaration of function 'tray_init' is invalid in C99 [-Wimplicit-function-declaration]
  if (tray_init(&tray) < 0) {
      ^
../example.c:100:10: warning: implicit declaration of function 'tray_loop' is invalid in C99 [-Wimplicit-function-declaration]
  while (tray_loop(1) == 0) {
         ^
3 warnings generated.
[4/4] Linking C executable tray_example

@dmikushin
Copy link
Owner

Ubuntu 18.04: yes, you are right, there are some issues fixed in 7dd6cb9 , please give it a try:

$ git clone [email protected]:dmikushin/tray.git
Cloning into 'tray'...
remote: Enumerating objects: 246, done.
remote: Counting objects: 100% (67/67), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 246 (delta 35), reused 62 (delta 33), pack-reused 179
Receiving objects: 100% (246/246), 601.53 KiB | 316.00 KiB/s, done.
Resolving deltas: 100% (137/137), done.
$ cd tray
$ mkdir build
$ cd build
$ cmake -G Ninja ..
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Checking for module 'appindicator3-0.1'
--   Found appindicator3-0.1, version 12.10.0
-- Configuring done
-- Generating done
-- Build files have been written to: /home/marcusmae/forge/tray/build
$ ninja
[1/4] Building C object CMakeFiles/tray_example.dir/example.c.o
../example.c: In function ‘quit_cb’:
../example.c:47:3: warning: implicit declaration of function ‘tray_exit’ [-Wimplicit-function-declaration]
   47 |   tray_exit();
      |   ^~~~~~~~~
../example.c: In function ‘main’:
../example.c:96:7: warning: implicit declaration of function ‘tray_init’ [-Wimplicit-function-declaration]
   96 |   if (tray_init(&tray) < 0) {
      |       ^~~~~~~~~
../example.c:100:10: warning: implicit declaration of function ‘tray_loop’ [-Wimplicit-function-declaration]
  100 |   while (tray_loop(1) == 0) {
      |          ^~~~~~~~~
[4/4] Linking C executable tray_example

@dmikushin
Copy link
Owner

Windows 10: yes, the rest of issues you reported are valid, and are fixed in 096bac7 . Below is the successful build log:

C:\>git clone https://github.com/dmikushin/tray.git
Cloning into 'tray'...
remote: Enumerating objects: 264, done.
remote: Counting objects: 100% (85/85), done.
remote: Compressing objects: 100% (48/48), done. eceiving objects:   8% (22/264)
remote: Total 264 (delta 49), reused 70 (delta 37), pack-reused 179
Receiving objects: 100% (264/264), 602.35 KiB | 3.67 MiB/s, done.
Resolving deltas: 100% (151/151), done.

C:\>cd tray

C:\tray>mkdir build

C:\tray>cd build

C:\tray\build>cmake -G Ninja .. 
-- The C compiler identification is MSVC 19.29.30133.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C://tray/build

C:\tray\build>ninja
[2/4] Building C object CMakeFiles\tray.dir\tray_windows.c.obj
cl : Command line warning D9025 : overriding '/MDd' with '/MTd'
C:\tray\tray_windows.c(40): warning C4244: 'function': conversion from 'WPARAM' to 'UINT', possible loss of data
C:\tray\tray_windows.c(140): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 
[4/4] Linking C executable tray_example.exe

@dmikushin
Copy link
Owner

@KamijoToma Thank you for this report. Could you please confirm the errors are gone with commit 096bac7 ? I will close the issue for now. Should the errors persist, please reopen the issue.

cgutman pushed a commit to cgutman/tray that referenced this issue Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants