Clang error linker command failed with exit code 1 use v to see invocation

Doing K&R using Xcode, in the Functions section I entered the code for their example of the power function as follows. #include int power(int m, int n); int main() { int i...

You missed the definition of function int power (int base, int n) which is given after your main ends on the next page of the book.

When you declare prototype of a function you need to define what it should do you just declared the power function and never defined that, that’s why you got error.

Include the following definition, your code will compile the way you wants it to be.

int power (int base, int n) {
    int i, p;
    p = 1;
    for (i=1; i<=n; ++i)
        p = p*base;
    return p;
}

Pre-edit answer

Now this is not relevant, but useful

I think you want to use function pow() defined in math.h.

double pow(double a, double b)

The C library function pow(double a, double b) returns a raised to the power of b. This function returns a double value so to print that correct specifier will be "%lf".

In this case you just need to include header file

#include <math.h>

In your program.

There is no need to give function declaration int power(int m, int n);

The error you are having is due to giveing I as on of the parameter to pow()
because when you will compile your code (after including math.h and using pow() replacing i with any integer numbers will compile your code and will give proper output.

printf("%lf %lf %lfn", i, pow(2, 3), pow(3, 2));

This will give you proper result but when you compile it with

for (i=0; i<10; ++i) {
    printf("%lf %lf %lfn", i, pow(2, i), pow(-3, i));
}

It throws same error so I think pow() takes only constants as input so it won’t run in for loop.

And if you don’t want to include math.h you can simply declare

extern double pow (double base, double exponent);

That will link correctly with the library code without using the math.h include file, here is an example.

int main() {
    extern double pow (double base, double exponent);
    printf("%lf", pow(8.0, 8.0));
    return 0;
}

For more on pow() you can check man page on Linux i.e. man pow.

Содержание

  1. clang: error: linker command failed with exit code 1 (use -v to see invocation)
  2. Replies
  3. Linker command failed with exit code 1 (use -v to see invocation) #297
  4. Comments
  5. clang: error: linker command failed with exit code 1 (use -v to see invocation) #2997
  6. Comments

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Just updated to the latest XCode. Big mistake. Why must Apple ruin my project everytime they update Xcode? I might give up on Swift development if I can’t get this fixed easily.

The error I get is: clang: error: linker command failed with exit code 1 (use -v to see invocation)

How should I go about fixing it? Already tried build clean and restarted XCode a bunch.

That message isn’t the error, it’s just a message telling you there is an error.

Go to the build log (click the last icon across the top of the navigator pane), expand the transcript with the error, and if necessary click the details icon to see the error message(s) produced by the linker.

Here is the error:

Ld /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator/name.app/PlugIns/nameTest.xctest/nameTests normal x86_64

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk -L/Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator -F/Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -filelist /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -mios-simulator-version-min=9.1 -bundle_loader /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator/appName.app/appName -Xlinker -object_path_lto -Xlinker /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests.swiftmodule -lsqlite3 -framework XCTest -Xlinker -dependency_info -Xlinker /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests_dependency_info.dat -o /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator/appName.app/PlugIns/appNameTests.xctest/appNameTests

ld: /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests.o compiled with newer version of Swift language (3.0) than previous files (2.0) for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Источник

Linker command failed with exit code 1 (use -v to see invocation) #297

Hello — I searched the issues here as well as in stackOverflow, but cannot seem to find a resolution to this problem.

I followed the manual instructions — https://github.com/mapbox/react-native-mapbox-gl/blob/master/ios/install.md — to install react-native-mapbox-gl for iOS, installing manually onto my Macbook Pro and I am using_ xCode 7.2.x_ .

I am getting an error in xCode and the project fails to build with the following error :

xCode is executing the following command:

general details —
*running react-native 0.2x (latest)
*used node 4.x stable to install react-native-mapbox-gl via npm
*Also changed the deployment target from iOS 7.x to 8.x and 9.x in xCode and still get the same results.

initial thought — do I have to add some file or folder to path? let me know.

Any help is appreciated. thanks — Edward

The text was updated successfully, but these errors were encountered:

Any chance you could post a screenshot of your Xcode setup? Can you verify you added the Mapbox framework in the embedded framework section?

@bsudekum thanks for responding. I will post a screenshot of xCode setup in a moment but yes I embedded the Mapbox framework in the embedded framework settings under the General Tab for my project.

In the meantime, I thought I would follow up with the following:

  1. looks like the process for creating Android version works (I was able to implement the example)
  2. I also attempted the cocoapods install. Got a similar linker error —

ld: library not found for -lPods- clang: error: linker command failed with exit code 1 (use -v to see invocation)

(even going further as to add the additional references to my podfile as you described further on in the iOS instructions and updating the node_modules references appropriately, this executed with no errors)
`
source ‘https://github.com/CocoaPods/Specs.git’

xcodeproj ‘projectName’
workspace ‘projectName’

pod ‘RCTMapboxGL’, :path => ‘../node_modules/react-native-mapbox-gl/ios’
pod ‘React’, :path => ‘../node_modules/react-native’
pod ‘React/RCTGeolocation’, :path => ‘../node_modules/react-native’
pod ‘React/RCTImage’, :path => ‘../node_modules/react-native’
pod ‘React/RCTNetwork’, :path => ‘../node_modules/react-native’
pod ‘React/RCTText’, :path => ‘../node_modules/react-native’
pod ‘React/RCTWebSocket’, :path => ‘../node_modules/react-native’
`

So having tried both methods on two mac machines I am currently stuck.

Here is the general order of steps I performed in image form as per your request @bsudekum

  1. install at command prompt
  2. add to project
  3. embed in general tab
  4. add run script in build phase
  5. add framework/library
  6. result of adding framework/library

I then implemented the example and built the project in Xcode.

Here was the result (from one of a number of multiple tests) @bsudekum .

specs:
*xCode 7.2.1
*simulator was set up as iphone5 / iOS 8.1,9.1,9.2 or iPhone 6s iOS 8.1,9.1,9.2
*fresh install for examples: npm / nvm, node 4.x, react-native 0.20 (they have since upgraded to 0.21)
*I am the admin of my machine with root access (if required)

I also ran the setup against cocoa pods (latest version) and had the native version of Ruby for OSX (I think 2.x) then upgraded to the latest version for OSX.

_notes: in a test I performed today (March 7th, over a week later) I was able to get the example iOS app running by launching the site from the _terminal* using the command react-native run-ios . but not in xCode on two different machines??
** I also noted that the manual instructions for iOS do not necessarily match the images provided , had to infer whether to add «bash» to the run script command for example, or when you right-click on your project to add files, do you add the RCTMapbox.xpcodeproj to the root of your project or in the libraries folder? — The choice you make determines whether xCode finds Mapbox.framework easily or not when you embed it in the general tab and it may be the cause of some issues (xCode might not find it on building the project and the icon indicates its ‘missing’)

I’m getting the same issue. Been following the guide for adding to Xcode manually, but getting the
framework not found Mapbox when trying to build the application.

My problem was that I initially did one of the steps wrong (added a library to the wrong path), and no matter if I fixed it it was broken.
Had to recreate the whole project, then it worked fine.

@frankbolviken so even just removing and re-adding the correct library and its path did not work for you? re-creating the entire project? strange, I will try.

@edward-at-intelex did you solve this problem?

I am experiencing the same issue. I have followed the guide exactly but still receive the error

I added following entry to Build Settings -> Framework Search Paths (Debug and Release) and it solved the problem on my machine:
$(PROJECT_DIR)/../node_modules/react-native-mapbox-gl (recursive)

Источник

clang: error: linker command failed with exit code 1 (use -v to see invocation) #2997

  • Operating System and version: MacOS Mojave 10.14.4
  • Compiler: CLion2018
  • PCL Version: 1.9.1

When I want to complier the PCL project, there are kinds of errors, for example:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [untitled] Error 1
make[2]: *** [CMakeFiles/untitled.dir/all] Error 2
make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
make: *** [untitled] Error 2
I have tried many ways except for reinstalling my system, but I failed, and there are no much similar situation. macOS 10.13 has not such problems.

I want to know if these problems are leaded by macOS10.14? Have any way to solve them? Thank you so much!

The text was updated successfully, but these errors were encountered:

I don’t think we will be able to help you with just this information. The error log just tells us you have a linking error. I’m still on High Sierra but we had Mojave users reporting successful compilation before.

Is it just version 1.9.1 that you’re not able to compile or also the current master branch?

I installed CMake and PCL through homebrew, I think that everything is up to date. I tried from December of last year and started from the newest PCL version, but there were always kinds of errors, including the cmake error about not finding glew.
Could you tell me about the installation process of the Mojave users who successful compilation, please?

I installed CMake and PCL through homebrew, I think that everything is up to date.

So it means that you’re not trying to compile PCL, but your own project which uses PCL. That wasn’t clear. If that’s the case and you’re having linking problems can you post the CMakeLists.txt file for your project?

I tried from December of last year and started from the newest PCL version, but there were always kinds of errors, including the cmake error about not finding glew.
Could you tell me about the installation process of the Mojave users who successful compilation, please?

I can’t help you with this. I’ve seen reports about that glew problem, but at this point migrating to Mojave is not an option for me and our CI infrastructure is still on High Sierra. However, it seems Mojave was deployed just last month to Azure Pipelines so we can upgrade it, see what happens and hopefully bump into whatever problem there might exist.

Your soonest response will be highly appreciated. Yes, I have not tried to compile PCL, just my own project uses PCL. I also think that you can have a try and to see what will happen after upgrade.

This is the CMakeLists.txt of my project:

cmake_minimum_required(VERSION 3.13)
project(T191_2)

add_executable(T191_2 main.cpp)
target_link_libraries(T191_2 $)

Try removing the following lines

I tried, but still the error.

And I compiled PCL1.9.1 with CMake just, there`s no problems.

Are you by chance getting the error ld: library not found for -lflann as well?

Are you by chance getting the error ld: library not found for -lflann as well?

That particular bug should be fixed already, although it wan’t released yet. Try to compile the current master and give it a try.

你偶然得到错误 ld: library not found for -lflann 吗?

Yes, sometimes. I have solved now, though it is not perfect. I install PCL1.8.1 first through homebrew, then new a project through CLion with C++ Standard 11. Then upgrade the PCL, succeed. But this way can not new a project again, because it will have the glew error in new projects.

Источник

@wigust

Hello,

I fail to getting started on GNU/Linux Ubuntu 16.04. I’ll attach configure, make, strace logs.

@wigust

@mgorges

Sorry, I am traveling thus my slow response. From the linking errors it seems that you are missing some 64bit related function calls.
[armeabi] SharedLibrary : libpayloadshared.so /home/miles/.lambdanative/tmp.vOcnTI/libpayload/libpayload.a(os_base.o):os_base.c:function ___alloc_mem_code: error: undefined reference to 'mmap64' /home/miles/.lambdanative/tmp.vOcnTI/libpayload/libpayload.a(os_base.o):os_base.c:function ___display_error: error: undefined reference to 'stderr' /home/miles/.lambdanative/tmp.vOcnTI/libpayload/libpayload.a(os_base.o):os_base.c:function ___set_signal_handler: error: undefined reference to 'sigemptyset'

To start debugging a bit more two questions:
a) Can you build successfully for another platform, like linux?
b) Could you rebuild after scrubbing the cache and provide those logs — I am wondering if the gambit build didn’t complete successfully?

Thanks Matthias

@mgorges

@danielsz

I see something similar. I was able to compile successfully for the linux platform. I am running Arch (which has the latest version of all dependencies). The output below is after running ./configure DemoHelloWorld android && make.

 => preparing JNI..
 => compiling payload module..
NDK_MODULE_PATH=/home/arch/daniel/.lambdanative/tmp.SJg6vd /opt/android-ndk/ndk-build --silent APP_ABI=armeabi
Android NDK: Found platform level in ./project.properties. Setting APP_PLATFORM to android-21.
/opt/android-ndk/build/core/setup-app.mk:81: Android NDK: Application targets deprecated ABI(s): armeabi
/opt/android-ndk/build/core/setup-app.mk:82: Android NDK: Support for these ABIs will be removed in a future NDK release.
[armeabi] Compile thumb  : payloadshared <= bootstrap.c
[armeabi] SharedLibrary  : libpayloadshared.so
/home/arch/daniel/.lambdanative/tmp.SJg6vd/libpayload/libpayload.a(os_base.o):os_base.c:function ___display_error: error: undefined reference to 'stderr'
/home/arch/daniel/.lambdanative/tmp.SJg6vd/libpayload/libpayload.a(2497115372.o):2497115372.c:function audiofile_select: error: undefined reference to 'stderr'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [obj/local/armeabi/libpayloadshared.so] Error 1
ERROR: failed with exit code 2
BUILD FAILED - configure with verbose option for more information
make: *** [Makefile:2: all] Error 1
```

@mgorges

@danielsz

Added:

SYS_CC=$android_cross"gcc $SYS_DEBUGFLAG -DANDROID -isysroot $android_sysroot $cflag_additions -D__ANDROID_API__=${ANDROIDAPI}"

Followed by make clean, then ./configure DemoHelloWorld android && make.

Output:

=== using profile Daniel Szmulewicz [/home/arch/daniel/scheme/lambdanative/PROFILE]..
=== configured to build DemoHelloWorld version 1.0 for android on linux in normal mode

==> checking for required tools..
==> checking for required libraries..
==> checking for lambdanative tools..
==> creating libraries needed for DemoHelloWorld..
 => liblambdanative..
 => cleaning up..
 => exploding library libgambc..
 => exploding library liblambdanative..
==> creating artwork needed for DemoHelloWorld..
==> creating textures needed for DemoHelloWorld..
==> creating fonts needed for DemoHelloWorld..
==> creating strings needed for DemoHelloWorld..
==> updating embedded files for DemoHelloWorld..
==> updating web assets for DemoHelloWorld..
 => compiling scheme payload..
    /home/arch/daniel/scheme/lambdanative/modules/config/config.scm ..
    /home/arch/daniel/scheme/lambdanative/modules/eventloop/eventloop.scm ..
    /home/arch/daniel/scheme/lambdanative/modules/ln_core/ln_core.scm ..
    /home/arch/daniel/scheme/lambdanative/modules/ln_glcore/ln_glcore.scm ..
    /home/arch/daniel/.cache/lambdanative/build/DemoHelloWorld/fonts/main-ascii.scm ..
    /home/arch/daniel/.cache/lambdanative/build/DemoHelloWorld/strings/main-title.scm ..
    /home/arch/daniel/scheme/lambdanative/modules/ln_glgui/ln_glgui.scm ..
    /home/arch/daniel/scheme/lambdanative/modules/audio/audio.scm ..
    /home/arch/daniel/scheme/lambdanative/modules/audioaux/audioaux.scm ..
    /home/arch/daniel/scheme/lambdanative/apps/DemoHelloWorld/main.scm ..
 => done compiling scheme payload
 => generating hook..
 => assembling payload..
 == /home/arch/daniel/.cache/lambdanative/android/lib/libpayload.a
==> creating android loader needed for DemoHelloWorld..
 => creating android project..
 => using target 2 [API 21]
 => preparing icons..
 => processing sounds needed for DemoHelloWorld..
 => processing sounds from /home/arch/daniel/scheme/lambdanative/apps/DemoHelloWorld/sounds...
 => /home/arch/daniel/scheme/lambdanative/apps/DemoHelloWorld/sounds/ahooga.wav..
 => transferring java hook..
 => transferring java public classes..
 => preparing manifest..
 => creating payload module..
 => preparing JNI..
 => compiling payload module..
NDK_MODULE_PATH=/home/arch/daniel/.lambdanative/tmp.Apiwkw /opt/android-ndk/ndk-build --silent APP_ABI=armeabi
Android NDK: Found platform level in ./project.properties. Setting APP_PLATFORM to android-21.
/opt/android-ndk/build/core/setup-app.mk:81: Android NDK: Application targets deprecated ABI(s): armeabi
/opt/android-ndk/build/core/setup-app.mk:82: Android NDK: Support for these ABIs will be removed in a future NDK release.
[armeabi] Compile thumb  : payloadshared <= bootstrap.c
[armeabi] SharedLibrary  : libpayloadshared.so
/home/arch/daniel/.lambdanative/tmp.Apiwkw/libpayload/libpayload.a(os_base.o):os_base.c:function ___display_error: error: undefined reference to 'stderr'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [obj/local/armeabi/libpayloadshared.so] Error 1
ERROR: failed with exit code 2
BUILD FAILED - configure with verbose option for more information
make: *** [Makefile:2: all] Error 1

@mgorges

Sorry, the NDK needs to get this flag passed as well. One way would be to change «CFLAG_ADDITIONS» so loaders/android/Android.mk.jni.in updates it too. The only way I currently see is either making two changes in android loader and target, or one in make.sh.

@mgorges

@danielsz

Same output after applying indicated changes to Android.mk.jni.in.

@mgorges

Too bad, then I’ll need to get myself a virtual machine with your version of Arch Linux and see how to investigate this further. For reference which versions of the Android NDK and SDK do you have installed?

@danielsz

Actually, it seems I needed to issue make scrub. This time around, I progressed further. Thank you.
A different issue came up:

[buildconfig] Generating BuildConfig class.
-pre-compile:
-compile:
    [javac] Compiling 3 source files to /home/arch/daniel/.lambdanative/tmp_build/bin/classes
    [javac] error: Source option 5 is no longer supported. Use 6 or later.
    [javac] error: Target option 1.5 is no longer supported. Use 1.6 or later.
BUILD FAILED

I run java 10. SDK is 26.1.1, and ndk is r16.b

@danielsz

Works with Java 8, though. Thank you. Build succeeded.

@mgorges

Thanks for trying some more options, and finding a successful one. Still a reason to explore the difference between Java 8 and 10 I should look into.

@danielsz

Yes, java 9 broke a lot of build workflows. It’s slightly annoying but it’s for the good cause (cruft removal).

More here if you’re interested.

Thank you for open sourcing lamdanative.I just started playing and find it intriguing. Definitely a compelling value proposal. Both because of the cross-platform aspect and the reliance on Scheme.

@danielsz

I saw the same linker error when installing apps that have dependencies (like DemoPhysics with the chipmunk dependency), indicating that there might be more places where C flags need to be set. Could that be the case?

@mgorges

Yes, it will probably need to go in lots of places but I have yet to figure out how to only set it once, instead of having to change a ton of different places.

@danielsz

OK, no problem, please let me know if I can help with testing.

@mgorges

I think the Java9/10 compatibility should have its own ticket. Also don’t know when I’ll be able to look into this further. Will look at the linker global addition piece tomorrow.

@danielsz

You are right.

I will wait for the global addition of C flags (that will propagate through gcc, NDK and project external dependencies) and test it when it lands in master. Thank you.

@mgorges

Fixed in 1e213e0, which specified the desired android API in both the CFLAG in the android build configuration as well as SYS_CC.

@danielsz

Thank you. Please note this doesn’t handle the case where dependencies are being used. In other words, the Calculator project compile fine for Android, but not DemoPhysics.

[armeabi-v7a] SharedLibrary  : libpayloadshared.so
/home/arch/daniel/.lambdanative/tmp.I8GbwN/libpayload/libpayload.a(chipmunk.o):chipmunk.c:function cpMessage: error: undefined reference to 'stderr'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [obj/local/armeabi-v7a/libpayloadshared.so] Error 1
ERROR: failed with exit code 2
BUILD FAILED - configure with verbose option for more information

@mgorges

I thought that worked — will have to look again this week.

@mgorges

@danielsz could you paste the full compilation log for DemoPhysics on android, as this does seem to work for me — I do get these lines int there, which seem appropriate: /Users/mgorges/Library/Caches/lambdanative/android/android-ndk-r13b-arm-19-toolchain/bin/arm-linux-androideabi-gcc -DANDROID -D__ANDROID_API__=19 -isysroot /Users/mgorges/Library/Caches/lambdanative/android/android-ndk-r13b-arm-19-toolchain/sysroot -Wall -std=gnu99 -DNDEBUG -DCP_USE_DOUBLES -I../include/chipmunk -c *.c

@mgorges

maybe you didn’t rebuild something after you pulled so you have mixed libraries still around?

@danielsz

That is very possible. What is the procedure I should follow after pulling?

@mgorges

I would typically say make scrub; configure DemoPhysics android; make, but this might be too much effort as it would rebuild everything for all platforms.

Thus, I’d suggest you manually clear the android build cache and then simply do a make — the cache folder is located at $HOME/lambdanative-cache, $HOME/.cache/lambdanative, or $XDG_CACHE_HOME/lambdanative depending on your system; within it you find an android folder, which contains a lib folder, removing only the later one should be sufficient to force a library rebuild.

@danielsz

Yup, that did it. Awesome. Thanks!

Replies

That message isn’t the error, it’s just a message telling you there is an error.

Go to the build log (click the last icon across the top of the navigator pane), expand the transcript with the error, and if necessary click the details icon to see the error message(s) produced by the linker.

Here is the error:

Ld /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator/name.app/PlugIns/nameTest.xctest/nameTests normal x86_64

cd /Users/name/Documents/Development/appName/appName

export IPHONEOS_DEPLOYMENT_TARGET=9.1

export PATH=»/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin»

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk -L/Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator -F/Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -filelist /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -mios-simulator-version-min=9.1 -bundle_loader /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator/appName.app/appName -Xlinker -object_path_lto -Xlinker /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests.swiftmodule -lsqlite3 -framework XCTest -Xlinker -dependency_info -Xlinker /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests_dependency_info.dat -o /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator/appName.app/PlugIns/appNameTests.xctest/appNameTests

ld: /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests.o compiled with newer version of Swift language (3.0) than previous files (2.0) for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

So the real error is the 2nd to last line of this:

ld: /Users/…/appNameTests.o compiled with newer version of Swift language (3.0) than previous files (2.0) for architecture x86_64

Swift currently requires all code in an application to be compiled with exactly the same version of the Swift compiler, and all code to use the same language syntax. (That’s because the ABI — application binary interface — that controls name mangling and calling conventions is different in these cases.) Your project apparently has some source files that haven’t been converted from Swift 2 to Swift 3.

Select the project item in the navigator pane, then go down the list of targets that’s displayed. For each one, use Edit -> Convert to check that it has been converted to Swift 3.

What did «preferredStyle: UIAlertControllerStyle.Alert» and «style: UIAlertActionStyle.Default» translate to in Swift 3.0? This is a mess.

In general, enum cases starting with a capital letter changed to a lower-case letter in Swift 3.

Note that when passing a parameter, the compiler can infer the type, so you don’t need (for example) to enter the type name. You can have just:

preferredStyle: .alert

I mention this because the easiest way to fix many of the syntax errors resulting from Swift 3 conversion by re-typing and letting autocomplete supply the correct syntax. In the above example, if you type the «.» for the style, autocomplete should pop up with a menu of valid styles.

> This is a mess.

Yes, Swift 3 syntax conversion doesn’t actually do all of the necessary conversions. In some cases, a different conversion error prevents it from changing something it otherwise should have (such as the capitalization of enum cases). In other cases, it just fails to convert some things.

But you should persevere. Swift 3 embraces the pain of conversion so that future Swifts don’t have to. At least, that’s the theory.

Thanks. I have a few more I need your help to translate to Swift 3.0:

let reference = CKReference(recordID: xxxx.recordID, action: .deleteSelf) //Complains that CKReferenceAction has no member deleteSelf but it will clearly let you select .deleteSelf

dispatch_async(NSDispatchQueue.main) {

} //Whats the deal with this one? Let’s me select NSDispatchQueue.main but complains «Use of unresolved identifier ‘NSDispatchQueue'»

let reference = CKReference(recordID: xxxx.recordID, action: .deleteSelf)

My guess is that this is a secondary error, and what’s really wrong is something to do with your recordID. Is that possible?

dispatch_async(NSDispatchQueue.main) { … }

GCD has been «wrapped» in a better API for Swift 3. Instead of the above, use

DispatchQueue.main.async { … }

For more information about the other classes and declarations, see:

developer.apple.com/reference/dispatch

Note that it’s just the APIs that have changed. The functionality is the same underneath.

The compiler doesn’t seem to recognize DispatchQueue.main.async { … } for some reason. What could be causing that?

Did you import Foundation? I can’t think of any other reason. What’s the exact error message?

It gives me the error «Use of unresolved identifier ‘DispatchQueue'». It won’t even give me the option to put «import Foundation» at the top of my code. It makes me pick «CoreFoundation» or «AVFoundation»

You don’t need «permission» to put «import Foundation» in your source file. Just type it.

Unfortunately, adding «import Foundation» at the top of the files affected did not fix the errors.

I’m still getting the error: Type ‘CKReferenceAction’ has no member .deleteSelf

For line: let reference = CKReference(recordID: record.recordID, action: .deleteSelf)

Also the error: Use of unresolved identifier ‘DispatchQueue’

For line: DispatchQueue.main.async { }

Any additional suggestions for how to fix this?

My guess is that this particular source file is still being compiled as Swift 2 instead of Swift 3. (After all, you started this thread with an error that told you there were mixed Swift versions in your link.)

Sorry it’s frustrating, but there must be something simple-but-obscure wrong.

For the DispatchQueue error.

Comment it out, then underneath begin typing it again and follow the autocomplete.

I just hashed up an empty project using Foundation and it had no issues with me including DispatchQueue.main.async.

As for your other issue try changing it to

let reference = CKReference(recordID: record.recordID, action: CKReferenceAction.DeleteSelf)

Thank you for your suggestion on the reference issue. That cleared up that issue.

But for DispatchQueue when I start typing, XCode does not give me an option to select DispatchQueue. Only «dispatch_queue_t», «DISPATCH_IO_STOP», etc.

  • Forum
  • General C++ Programming
  • linker command failed with exit code 1

linker command failed with exit code 1

Hi, I’m currently working on this code, but it keeps on giving me this error:»linker command failed with exit code 1″ and I can’t figure out how to get rid of it?

MyInteger.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "MyInteger.hpp"
#include <iostream>

MyInteger::MyInteger(int num)
{
    pInteger = new int;
    num = *pInteger;
}

MyInteger::~MyInteger()
{
    delete pInteger;
}

MyInteger::MyInteger(const MyInteger &copy)
{
    pInteger = new int;
    *pInteger = *copy.pInteger;
}

MyInteger  MyInteger::operator=(const MyInteger &overloadCopy)
{
    pInteger = new int;
    *pInteger = *overloadCopy.pInteger;
    return overloadCopy;
}

int MyInteger::getMyInt()
{
    return *pInteger;
}

void MyInteger::setMyInt(int num)
{
    pInteger = new int;
    *pInteger = num;
}

MyIntegerMain.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "MyInteger.cpp"
#include "MyInteger.hpp"
#include <iostream>

int main()
{
    MyInteger obj1(17);
    MyInteger obj2 = obj1;
    std::cout << obj1.getMyInt() << std::endl;
    std::cout << obj2.getMyInt() << std::endl;
    
    obj2.setMyInt(9);
    std::cout << obj1.getMyInt() << std::endl;
    std::cout << obj2.getMyInt() << std::endl;
    
    MyInteger obj3(42);
    obj2 = obj3;
    std::cout << obj2.getMyInt() << std::endl;
    std::cout << obj3.getMyInt() << std::endl;
    
    obj3.setMyInt(1);
    std::cout << obj2.getMyInt() << std::endl;
    std::cout << obj3.getMyInt() << std::endl;
    
    return 0;
}

Thank you!

Last edited on

MyInteger obj2 = obj1;
On the left, you’re trying to use the non-existent default constructor.

While I’m here, num = *pInteger; on line 7 looks wrong

Hi, thanks for the reply.

Shouldn’t MyInteger obj2 = obj1 invoke the copy constructor?

and I’m sure why is num = *pInteger wrong?

Thank you!

Shouldn’t MyInteger obj2 = obj1 invoke the copy constructor?

It should call the assignment operator.

Why does this class have an int pointer instead of just an int?

but it keeps on giving me this error:»linker command failed with exit code 1″

Read your compile/linker error messages, they should tell you what is wrong.

What does your include file contain?

By the way you shouldn’t be #including your source file. Source files should be added to your project/build line to be compiled not #included.

The class has an int pointer instead of just an int because the teacher wanted us to do it that way…. For some reason.

my include file is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef MyInteger_hpp
#define MyInteger_hpp

class MyInteger
{
private:
    int *pInteger;
public:
    MyInteger();
    MyInteger(int);
    ~MyInteger();
    MyInteger(const MyInteger&);
    MyInteger operator=(const MyInteger &);
    void setMyInt(int);
    int getMyInt();
};

#endif /* MyInteger_hpp */ 

And the error messages is

1
2
ld: 11 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Last edited on

ld: 11 duplicate symbols for architecture x86_64

This is probably being caused by #including the source file.

> ld: 11 duplicate symbols for architecture x86_64
don’t cut the message. prior to that it should have told you what symbols were duplicated.
also, when asking about linker errors you should show the build command, because the error may be there.

This. Use all information. Provide all information. If you do not know what is relevant, then assume that everything is.

A build has multiple steps.
* Compilation: compiler produces an object file for each translation unit.
Within compilation preprocessor prepares translation unit for the compiler.
* Linking: linker combines object files and libraries into binary.

If one gets a linker error, that means that compilation step has succeeded. The compiler has not encountered objectionable syntax (although code can be full of logical errors).

When you see an error, there can be multiple lines of it. (I’ve heard of «simple» syntax error generating 1000 lines of output.) Focus on the first, not the last. After the first error the system can already be so «off the track» that the rest of the error messages are nonsense.

>>why is num = *pInteger wrong?

the function of a constructor is to initialize the value of class data, that doesn’t
seem to be the case here with «num»

1
2
3
4
5
MyInteger::MyInteger(int num)
{
    pInteger = new int;
    num = *pInteger; /// should be *pInteger = num
}

Last edited on

Thanks guys for all the help, the reason why I was getting that error message was because I included the wrong file. It works fine now.

Thanks again!

Topic archived. No new replies allowed.

Понравилась статья? Поделить с друзьями:
  • Clamav ошибка обновления
  • Clamav scanning error 8 init error
  • Clack ошибка 103
  • Clack ошибка 102
  • Clack ошибка 101