Ϊʲôͬһ¸öÏîÄ¿Á½¸öc³ÌÐò¾Í²»ÄÜÔËÐÐÁË
ͼƬΪ´úÂëÏÂÃæÊDZ¨´íÌáÐÑ
====================[ ¹¹½¨ | test | Debug ]=======================================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build "/Volumes/My file/C/github/test/cmake-build-debug" --target test -j 6
Linking C executable test
FAILED: test
: && /Library/Developer/CommandLineTools/usr/bin/cc -g -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_namesCMakeFiles/test.dir/hello.c.o CMakeFiles/test.dir/100.c.o -o test && :
duplicate symbol '_main' in:
/Volumes/My file/C/github/test/cmake-build-debug/CMakeFiles/test.dir/100.c.o
/Volumes/My file/C/github/test/cmake-build-debug/CMakeFiles/test.dir/hello.c.o
ld: 1 duplicate symbols
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Õâ¸ö´íÎóÊÇÒòΪÁ½¸ö³ÌÐò¶¼¶¨ÒåÁËÒ»¸öÃûΪ¡°main¡±µÄº¯Êý£¬Õâ¸öº¯ÊýÊdzÌÐòµÄÈë¿Úµã£¬Òò´ËÔÚÁ´½Óʱ·¢ÉúÁ˳åÍ»¡£Òª½â¾öÕâ¸öÎÊÌ⣬ÄãÐèҪȷ±£Ã¿¸ö³ÌÐò¶¼ÓÐ×Ô¼ºµÄΨһµÄ¡°main¡±º¯Êý¡£Äã¿ÉÒÔ½«ÆäÖÐÒ»¸ö³ÌÐòÖеġ°main¡±º¯ÊýÖØÃüÃûΪÆäËûÃû³Æ£¬»òÕß½«Æä·ÅÔÚÒ»¸öµ¥¶ÀµÄÎļþÖУ¬²¢½«ÆäÓëÆäËûÎļþÁ´½Ó¡£ ÎÊÌâÔÒò£º
ÄãµÄ±¨´íÐÅÏ¢ÌáʾÓÐÖظ´µÄ·ûºÅ "_main"£¬ÕâÊÇÓÉÓÚÁ½¸öC³ÌÐòÖж¼°üº¬ÁËÏàͬµÄÖ÷º¯Êýµ¼Öµġ£
½â¾ö·½·¨£º
ÔÚÒ»¸öÏîÄ¿ÖУ¬Ö»ÄÜÓÐÒ»¸öÖ÷º¯Êý£¨mainº¯Êý£©¡£Òò´Ë£¬ÄãÐèҪȷ±£Ã¿¸öC³ÌÐòÓÐ×Ô¼º¶ÀÁ¢µÄÖ÷º¯Êý£¬²¢ÇÒÔÚ±àÒëʱֻѡÔñÆäÖÐÒ»¸ö½øÐй¹½¨¡£
ÒÔÏÂÊǽâ¾ö²½Ö裺
1. È·±£Ã¿¸öC³ÌÐò¶¼ÓÐ×Ô¼º¶ÀÁ¢µÄÖ÷º¯Êý£¨mainº¯Êý£©¡£Ö÷º¯ÊýÊdzÌÐòµÄÈë¿Úµã£¬Ã¿¸ö³ÌÐòÖ»ÄÜÓÐÒ»¸öÖ÷º¯Êý¡£
2. ÔÚCLionÖдò¿ªÄãµÄÏîÄ¿£¬²¢Ñ¡ÔñÆäÖÐÒ»¸öC³ÌÐò×÷ΪÈë¿Ú³ÌÐò¡£
3. ÔÚCLionµÄ¹¤¾ßÀ¸ÉÏÕÒµ½²¢µã»÷ "Edit Configurations"£¨»òÕßÑ¡Ôñ "Run" -> "Edit Configurations"£©¡£
4. ÔÚµ¯³öµÄ¶Ô»°¿òÖУ¬Ñ¡ÔñÄãµÄÅäÖò¢µã»÷ "Delete"£¨É¾³ý£©°´Å¥¡£Õ⽫´ÓÅäÖÃÁбíÖÐɾ³ý¸ÃÅäÖá£
5. ÏÖÔÚ£¬Äã¿ÉÒÔ³¢ÊÔÖØй¹½¨ºÍÔËÐÐÄãµÄÏîÄ¿£¬È·±£Ñ¡ÔñÁËÕýÈ·µÄC³ÌÐò×÷ΪÈë¿Ú¡£
Öظ´ÒÔÉϲ½Ö裬ȷ±£Ã¿¸öC³ÌÐò¶¼ÓÐ×Ô¼º¶ÀÁ¢µÄÈë¿Ú£¬²¢ÇÒÔÚÿ´Î¹¹½¨ºÍÔËÐÐʱѡÔñÕýÈ·µÄ³ÌÐò¼´¿É¡£
Ï£ÍûÕâÄܽâ¾öÄãµÄÎÊÌ⣡Èç¹ûÄ㻹ÓÐÆäËûÎÊÌ⣬ÇëËæʱÌáÎÊ¡£
ÇòÒ»¸ö×î¼Ñ´ð°¸Ð»Ð»À²£¡Õâ¶ÔÎҷdz£ÖØÒª£¡{:10_254:}{:10_254:}{:10_254:}
Ò³:
[1]