Comments (8)
First of all, can you post your CMakeLists.txt? libnx is already linked in automatically as a system lib, you don't need to manually ask for it. During our testing, we found it sufficed to use this to link in deko3d:
target_link_libraries (${PROJECT_NAME} PRIVATE
deko3dd
)
from libnx.
@fincs I managed to reproduce the issue with a basic sample. It turns out nwindowGetDefault()
cannot be called from C++, only from C. I've attached a reproduction to this comment. If you rename main.cpp
to main.c
and update the CMakeLists.txt to reference it, the build will succeed, and by default it will fail.
For reference I generate a Makefile with the following command:
cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../cmake/DevkitA64Libnx.cmake ..
from libnx.
Here's the full build output demonstrating the issue:
Scanning dependencies of target sample
[ 25%] Building CXX object CMakeFiles/sample.dir/main.cpp.obj
/Users/lyptt/Desktop/sample/main.cpp: In function 'int main()':
/Users/lyptt/Desktop/sample/main.cpp:4:12: warning: variable 'a' set but not used [-Wunused-but-set-variable]
4 | NWindow* a = nwindowGetDefault();
| ^
[ 50%] Linking CXX executable sample
/opt/devkitpro/devkitA64/bin/../lib/gcc/aarch64-none-elf/11.1.0/../../../../aarch64-none-elf/bin/ld: /opt/devkitpro/devkitA64/bin/../lib/gcc/aarch64-none-elf/11.1.0/../../../../aarch64-none-elf/bin/ld: DWARF error: can't find .debug_ranges section.
CMakeFiles/sample.dir/main.cpp.obj: in function `main':
main.cpp:(.text.startup.main+0x8): undefined reference to `nwindowGetDefault()'
collect2: error: ld returned 1 exit status
make[2]: *** [sample] Error 1
make[1]: *** [CMakeFiles/sample.dir/all] Error 2
make: *** [all] Error 2
from libnx.
As I suspected, you're using third party/unsupported cmake machinery. You might be interested to know that, as of recently, we've added official cmake toolchain support. You can get it by installing or refreshing your switch-dev package group installation, i.e. sudo dkp-pacman -S --needed switch-dev
.
In order to use it, we offer a wrapper script that sets the correct variables: /opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake
. It is advised to purge your project of traces of previous unsupported machinery, and move to our new official support.
Setting up a basic project with deko3d should be as simple as this:
cmake_minimum_required (VERSION 3.7)
project (MyProjectName)
add_executable (${PROJECT_NAME}
# Source code files go here
source/main.cpp
)
dkp_add_asset_target (${PROJECT_NAME}_romfs romfs)
nx_generate_nacp (${PROJECT_NAME}.nacp
NAME "Your Project Name"
AUTHOR "Author Name"
)
nx_create_nro (${PROJECT_NAME}
NACP ${PROJECT_NAME}.nacp
ROMFS ${PROJECT_NAME}_romfs
)
target_compile_options (${PROJECT_NAME} PRIVATE
-g -Wall -O2
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti>
)
target_link_libraries (${PROJECT_NAME} PRIVATE
deko3dd
)
# Shaders
nx_add_shader_program (simple_vsh simple_vsh.glsl vert)
nx_add_shader_program (simple_fsh simple_fsh.glsl frag)
dkp_install_assets (${PROJECT_NAME}_romfs
DESTINATION shaders
TARGETS
simple_vsh
simple_fsh
# etc
)
from libnx.
@fincs I've confirmed that C++ name mangling is the issue here. If it's intended that this API has C linkage, you'll need to wrap the header definitions in an extern "C" block. Doing this manually myself on my local copy of native_window.h
fixed the linking issue.
I've attached the modified file so you can see the change.
from libnx.
Thanks for a sample of the supported approach, I couldn't find any examples yesterday of using libnx with cmake when I started playing around with it, so I had to go my own route.
from libnx.
Oh and one more thing. The header you need to include is #include <switch.h>
, which does have C++ guards. Trying to manually include libnx headers piecemeal is currently not supported.
from libnx.
Gotcha, I didn't see any documentation relating to that quirk of the toolchain either. I'll bear that in mind from now on. Thanks for the help.
from libnx.
Related Issues (20)
- inet_pton() failure for 0.0.0.0
- Can't open file sys/lock.h HOT 1
- Rotated/Normalized controller layouts using the pad abstraction API HOT 2
- Question: Home button HOT 3
- SL/SR buttons usage on hiddbg HOT 6
- Linear framebuffer crashes on certain dimensions HOT 2
- hidScanInput() was not declared in this scope HOT 6
- When i try to compile a .nro in devkitpro, i get this error: HOT 3
- web applet fails to connect to local server running on the switch HOT 17
- Question: Video HW Decoder HOT 9
- Nintendo HOT 1
- make a relase/how to compile it HOT 2
- ASCII Usage of "\" HOT 2
- Problem to print special chars in console mode HOT 4
- bool to pointer
- Wrong Github (sorry)
- Support: How to get a list of installed DLCs? HOT 2
- devkitPro on NixOS? HOT 1
- Support for HID Vibrations HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libnx.